Dynamic cron schedules #1237
-
👋 I'm looking for a programmatic way to add cron schedules without defining them in my For example, I would like to convert the following predefined schedule into plain Ruby.
config.good_job.cron = {
test_task: {
cron: "* * * * *",
class: "TestJob",
}
} What I tried:
Does someone have an example if this is currently possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What do you mean by "plain ruby"? The configuration is a Ruby hash and you can use procs/lambdas to set values dynamically. These values are tricky because the configuration must be set up when the application boots. What is feature in your application you're trying to do? |
Beta Was this translation helpful? Give feedback.
Unfortunately GoodJob doesn't have anything like that, and I don't think it's a good fit for GoodJob. GoodJob's cron all lives together in memory in each process, so each cron entry uses a little bit of memory and uses a little bit of CPU when it runs; it's not intended to be unbounded or dynamic
I'd imagine if you wanted something like this, that you'd build your own scheduler-like-behavior as part of your application: Run a job every minute, query for records that would be expected to run, run them, and then mark them as run until their next tick (e.g. just keep bumping their last_run_at and next_run_at)