首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用任意gem通过capistrano进行部署

无法使用任意gem通过capistrano进行部署
EN

Stack Overflow用户
提问于 2015-08-12 00:35:32
回答 1查看 1.2K关注 0票数 1

我正在尝试使用Capistraino部署Ruby on Rails应用程序。我有一个作业,我计划在任何时候使用,但我在尝试部署时不断收到错误。

下面的配置deploy.rb出错

代码语言:javascript
运行
复制
SSHKit::Runner::ExecuteError: Exception while executing as deploy@staging.company.com: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: config/schedule.rb:2:in `block in initialize': uninitialized constant Whenever::JobList::Delayed (NameError)
    from /home/deploy/app/company/shared/bundle/ruby/2.1.0/gems/whenever-0.9.4/lib/whenever/job_list.rb:44:in `every'
    from config/schedule.rb:1:in `initialize'

deploy.rb

代码语言:javascript
运行
复制
# delayed-job
set :delayed_job_workers, 2
set :delayed_job_prefix, :drnow
set :delayed_job_roles, [:app, :background]

# whenever
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :whenever_command, 'bundle exec whenever'
set :whenever_environment, defer { stage }

如果我将deploy.rb更改为

deploy.rb

代码语言:javascript
运行
复制
# whenever
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :whenever_command, 'bundle exec whenever'
set :whenever_environment, ->{ fetch :rails_env, fetch(:stage, "production") }

我得到了这个错误

错误

代码语言:javascript
运行
复制
DEBUG [e84fec09] Command: bundle exec whenever
DEBUG [e84fec09]    Could not locate Gemfile or .bundle/ directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@company.com: bundle exec whenever exit status: 10
bundle exec whenever stdout: Could not locate Gemfile or .bundle/ directory
bundle exec whenever stderr: Nothing written

SSHKit::Command::Failed: bundle exec whenever exit status: 10
bundle exec whenever stdout: Could not locate Gemfile or .bundle/ directory
bundle exec whenever stderr: Nothing written

Tasks: TOP => whenever:update_crontab
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@company.com: bundle exec whenever exit status: 10
bundle exec whenever stdout: Could not locate Gemfile or .bundle/ directory
bundle exec whenever stderr: Nothing written

Capfile

代码语言:javascript
运行
复制
# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
require 'capistrano/faster_assets'
require 'capistrano/delayed-job'
require 'whenever/capistrano'
# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

schedule.rb

代码语言:javascript
运行
复制
unless ENV['RAILS_ENV'] == 'test'
  every 30.minutes do
    Delayed::Job.enqueue(UpdateScoresJob.new(Article.published.all.pluck(:id)), priority: 1, run_at: 1.minute.from_now)
  end
end
EN

回答 1

Stack Overflow用户

发布于 2015-08-12 02:15:16

它似乎在抱怨找不到常量Delayed::Job。根据this github issue的说法,schedule.rb文件中没有加载完整的Rails环境。您可能希望将延迟的作业入队放在runner中,如下所示:

代码语言:javascript
运行
复制
unless ENV['RAILS_ENV'] == 'test'
  every 30.minutes do
    runner 'Delayed::Job.enqueue(UpdateScoresJob.new(Article.published.all.pluck(:id)), priority: 1, run_at: 1.minute.from_now)'
  end
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31947304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档