I am looking for a flow in ruby through which I can run a task daily on some particular times. I want to add a new task in some table, specify the time in some column and the task should be scheduled daily since the row has been added to the table. I know the gem 'whenever' is used for scheduling but it would require a code deployment whenever I need to specify the time in schedule.rb. Is it even possible what I want to do?
Asked
Active
Viewed 299 times
1
-
Are you able to access and use the rails console to set the jobs? or do you have to update the database directly and have the gem detect the change? – Tom Dec 26 '18 at 17:15
-
@Tom let's say I have a rule which needs to be triggered at some time. So what I want is that I could add a rule in a rule table, add a trigger in the trigger table to execute the rule at 6 pm daily. The gem automatically detects the new trigger and start scheduling it daily. – walt3rwhite Dec 26 '18 at 18:09
1 Answers
0
I think you can use crone gem this is purely writing in ruby, you do not need to set cron job like whenever gem. but how it work is cron in linux
installation steps:
gem 'crono'
rails generate crono:install
rake db:migrate # to install it's table
you can merge with active job
class TestJob # This is not an Active Job job, but pretty legal Crono job.
def perform(*args)
# put you scheduled code here
# Comments.deleted.clean_up...
end
end
and do the scheduling as follow (no need to set from OS / cron)
# config/cronotab.rb
Crono.perform(TestJob).every 2.days, at: {hour: 15, min: 30}
Crono.perform(TestJob).every 1.week, on: :monday, at: "15:30"

widjajayd
- 6,090
- 4
- 30
- 41