Monday 15 August 2011

ruby on rails - Struggling with the deployment of whenever cron jobs -



ruby on rails - Struggling with the deployment of whenever cron jobs -

i have rails 4 application deployed capistrano 3. lately tried adding cron jobs using whenever gem.

the problem when deploy- none of schedule.rb jobs aren't exists. also, don't see of log files generated in log path- ...path/to/app/shared/log/

here's configuration: gemfile:

# utilize whenever schedule jobs using cron gem 'whenever', :require => false

capfile: (added appropriate require based on whenever docs)

require 'whenever/capistrano'

deploy.rb:

### see great guid on in http://www.talkingquickly.co.uk/2014/01/deploying-rails-apps-to-a-vps-with-capistrano-v3/ ### # config valid capistrano 3.1 lock '3.2.1' # set local variables: application = 'eng_performance' home = '/home/deploy' set :application, application set :repo_url, "git@gitlab.com:danklei/#{application}.git" set :branch, 'smartadmin1_4_1' # set server deploy path of application set :deploy_to, "/var/www/#{application}" # set linked-files in order share secret files without deploying them db. set :linked_files, %w{config/database.yml config/jenkinscredentials.yml} # set directories want symlinking share set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} # set specs should run before deployment allowed go on (see lib/capistrano/tasks/run_tests) set :tests, [] # set config files should copied deploy:setup_config # see documentation in lib/capistrano/tasks/setup_config.cap # details of operations set(:config_files, %w( database.example.yml jenkinscredentials.example.yml )) namespace :deploy desc 'restart application' task :restart # on roles(:app), in: :sequence, wait: 5 on roles(:web), in: :sequence, wait: 5 # restart phusion passenger info 'restarting phusion passenger service' execute :touch, release_path.join('tmp/restart.txt') end end desc "update application's crontab entries using whenever" task :update_crontab setup_whenever_task |host| roles = host.roles_array.join(",") [fetch(:whenever_update_flags), "--roles=#{roles}"] end end after :publishing, :restart after :restart, :clear_cache on roles(:web), in: :groups, limit: 3, wait: 10 # here can such as: # within release_path # execute :rake, 'cache:clear' # end end end after :clear_cache, :update_crontab end after :deploy, "app_setup:create_tests_log_symlink"

schedule.rb:

# utilize file define of cron jobs. # # it's helpful, not exclusively necessary understand cron before proceeding. # http://en.wikipedia.org/wiki/cron set :output, {:error => "#{path}/log/cron_error_log.log", :standard => "#{path}/log/cron_log.log"} every 1.minute command "date" <-- sanity job create sure started working end every 1.day, at: "8:42" command "echo updating golden_results db relation rake task: update_golden_results" rake "golden:update_golden_results[false,true]" end every :reboot, :roles => [:web] rake "golden:refresh_golden_comparison" end every 1.day, at: "4am", :roles => [:web] command "echo refreshing rails cache rake task: golden:refresh_golden_comparison" rake "golden:refresh_golden_comparison" end every 1.week, at: "4am", :roles => [:web] command "echo updating golden_results db relation rake task: update_golden_results" rake "golden:update_golden_results[false,false]" end

note: i've added whenever provided whenever.rake file /app/lib/capistrano/tasks/whenever.rake , copied :update_crontab task deploy.rb file didn't know best practice of using that.

i'd appreciate help... thanks!

try this: if don't specify before please add together deploy.rb file

set :whenever_environment, defer { stage #define either production or staging whichever using here }

and

deploy.rb

desc "update application's crontab entries using whenever" task :update_crontab on roles(:web, :db, :app), in: :groups, limit: 3, wait: 10 setup_whenever_task |host| roles = host.roles_array.join(",") [fetch(:whenever_update_flags), "--roles=#{roles}"] end end before :deploy, :update_crontab

update:

off course of study can sysntax different

set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }

it in whenever github link please check 1 time https://github.com/javan/whenever

ruby-on-rails ruby-on-rails-4 cron capistrano whenever

No comments:

Post a Comment