ruby - cron job generated by whenever/capistrano for a Sinatra app sets the wrong environment variable -


i using whenever gem in sinatra app create cron job. using whenever/capistrano job created/updated on deploy. whenever setup of deploy script:

require 'whenever/capistrano' set :environment_variable, 'rack_env' set :whenever_roles,        ->{ :app } set :whenever_command,      ->{ [:bundle, :exec, :whenever] } set :whenever_command_environment_variables, ->{ { rack_env: fetch(:whenever_environment), rails_env: nil } } set :whenever_identifier,   ->{ "#{fetch(:application)}_#{fetch(:stage)}" } set :whenever_environment,  ->{ fetch :rack_env, fetch(:stage, "production") } set :whenever_variables,    ->{ "environment=#{fetch :whenever_environment}" } set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" } set :whenever_clear_flags,  ->{ "--clear-crontab #{fetch :whenever_identifier}" } 

when deploy, can see capistrano runs crontab update , seems proper environment variable going used:

info [8b4f49a6] running ~/.rvm/bin/rvm default bundle exec whenever --update-crontab sidekiq-monitor-ua_staging --set environment=staging --roles=app deploy@10.0.254.37 debug [8b4f49a6] command: cd /var/www/sidekiq-monitor-ua/releases/20160725170122 && ( rack_env=staging rails_env= ~/.rvm/bin/rvm default bundle exec whenever --update-crontab sidekiq-monitor-ua_staging --set environment=staging --roles=app ) debug [8b4f49a6]        [write] crontab file updated 

however, in crontab (this generated deploying staging environment):

# begin whenever generated tasks for: sidekiq-monitor-ua_staging 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /var/www/sidekiq-monitor-ua/releases/20160725170122 && rails_env=staging bundle exec rake log_sidekiq_status --silent >> /dev/null 2>&1'  # end whenever generated tasks for: sidekiq-monitor-ua_staging 

consequently, when crontab runs rake task, rack_env not set , code doesn't run because defaults development environment.

i either missing or have misconfigured. hope can help.

the environment_variable mentioned in whenever github readme job types: https://github.com/javan/whenever#define-your-own-job-types

the default rake job here

job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output" job_type :runner, "cd :path && bin/rails runner -e :environment ':task' :output"

:environment_variable default 'rails_env'

you can try below.

require 'whenever/capistrano' set :environment_variable, 'rack_env' set :whenever_roles,        ->{ :app } set :whenever_command,      ->{ [:bundle, :exec, :whenever] } set :whenever_command_environment_variables, ->{ {} } set :whenever_identifier,   ->{ "#{fetch(:application)}_#{fetch(:stage)}" } set :whenever_environment,  ->{ fetch :rack_env, fetch(:stage, "production") } set :whenever_variables,    ->{ "'environment=#{fetch :whenever_environment}&environment_variable=rack_env'" } set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" } set :whenever_clear_flags,  ->{ "--clear-crontab #{fetch :whenever_identifier}" } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -