简体   繁体   中英

how can i trigger a rake task on every 4th sunday of every month in rails?

i am having a rake task. i want that task to be scheduled to run on every 4th Sunday of every month. i am using whenever gem. how can i define logic in config/schedule.rb so that it will run on every 4th Sunday of every month in Rails? please help me.

this is my rake task app/lib/tasks/my_task.rake .

task :do_something => :environment do

end

this is my code in config/schedule.rb

every :sunday, :at => '12pm' do 
  runner "Employee.make_checkin_out"
end

how can i change the above logic?

whenever gem gives a facility to generate a cron job. This is a scheduler for rake tasks. You can define like

every 1.month, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_morning_every_month"
end

If you want something like 1st sunday every month use cron editor like

0 12 1-7 * * [ "$(date '+\\%a')" = "Sun" ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM