I am building a small crawler/scraper for my dad! I am trying to randomize scrape times every week (meaning I want the scrape method to fire off every week at a different day and time of day).
I tried the rewrite the YAML file every time the method fires off that does not seem to work... Then I tried the "set" method:
def set_random_schedule(author_name)
cron_expression = random_cron_expression
self.class.set(cron: cron_expression).perform_async(author_name)
end
def random_cron_expression
"#{rand(1..3)} * * * *}"
end
In the logs it said it was running almost every second, I honestly don't know why... Or if I read it wrong I am really new to sidekiq and cron so I am not sure where did I go wrong. Bare with me here please.
Any help to beginner? Feel free to explain or reference whatever comes to mind I am always keen to learn.
At the end of your job, you can try to add this code to reschedule its cron timer: