I have added the sidekiq scheduler by using sidekiq-scheduler gem in rails, but we are unable to add the dynamic date on the scheduler. Does anyone idea how to change the scheduler in dynamic.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
If you need to schedule jobs dynamically with Sidekiq, you can use the
perform_at
orperform_in
methods which allow you to set a specific date or delay for when the job should be performed.Here’s an example:
The
perform_in
method schedules a job to be performed after a certain amount of time, specified as an argument. Theperform_at
method schedules a job to be performed at a specific time, provided as aTime
object.However, if you need to dynamically set the schedule based on some external configuration or criteria, you might want to control Sidekiq’s schedule at runtime.
This is possible using the sidekiq-scheduler’s dynamic schedule feature:
You can call
Sidekiq.set_schedule
from anywhere in your application (for example, in a Rails initializer or a config file) and it will update the schedule in memory.Remember to enable the dynamic setting in your Sidekiq configuration:
You might need to call
Sidekiq.reload_schedule!
after you change the schedule to ensure the new schedule gets loaded.Remember that these dynamic schedules will be reset if the Sidekiq process restarts, as they’re only kept in memory. If you want to persist these dynamic schedules, you’d need to store them in some kind of persistent storage (like a database or a file) and then load them into Sidekiq when your application starts.
Hope this helps!