1

I'm trying to deploy a Ruby on Rails application using Capistraino. I have a job that I schedule using Whenever but I keep getting errors when trying to deploy.

error with config deploy.rb below

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

# 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 }

If I change deploy.rb to

deploy.rb

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

I get this error

error

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

# 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

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
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188

1 Answers1

1

It seems that it may be complaining about not being able to find the constant Delayed::Job. According to this github issue, the full Rails environment is not loaded in your schedule.rb file. You probably want to place your Delayed Job enqueue in a runner, like so:

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
Anthony Atkinson
  • 3,101
  • 3
  • 20
  • 22
  • It still throws the bundler error `(Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as deploy@staging.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` – Antarr Byrd Aug 11 '15 at 18:28
  • Do you have `set :deploy_to, '/rails/root'` anywhere in your Capistrano setup, and also, is your Gemfile committed? – Anthony Atkinson Aug 12 '15 at 14:52
  • Deploy to is set to the application root dir and yes Gemfile is commited – Antarr Byrd Aug 12 '15 at 15:29
  • After changing whereever path to `set :whenever_command, 'cd ~/app/myapplication/current && bundle exec whenever'` I get a new error. – Antarr Byrd Aug 12 '15 at 15:32
  • `cd ~/app/myapplication/current && bundle exec whenever stderr: config/schedule.rb:3:in 'block in initialize': uninitialized constant Whenever::JobList::Delayed (NameError) from /home/deploy/app/myapp/shared/bundle/ruby/2.1.0/gems/whenever-0.9.4/lib/whenever/job_list.rb:44:in 'every' from config/schedule.rb:2:in 'initialize' ` – Antarr Byrd Aug 12 '15 at 15:33