如何用sidekiq-scheduler配置工作日9-18点每分钟执行的任务?
Hey there! Great question — yes, absolutely! Sidekiq-scheduler leans on standard cron expressions, which are ideal for this kind of precise, time-bound scheduling that excludes weekends.
Here's exactly how you'd set this up in your schedule.yml file:
# Example configuration for your worker daily_weekday_worker: cron: "* 9-17 * * 1-5" class: "YourWorkerClassName" queue: default # Optional: Set a specific timezone to avoid server timezone mismatches # timezone: "Asia/Shanghai"
Let's break down what this cron expression does:
*: Runs every minute (the first asterisk targets the minute field)9-17: Executes only between 9 AM and 5:59 PM (this covers your 9 AM to 6 PM window, since the last run at 5:59 PM is right before 6 PM)*: Applies to every day of the month*: Applies to every month1-5: Restricts execution to Monday through Friday (weekdays; 1 = Monday, 5 = Friday — this excludes Saturdays and Sundays)
Quick note on the 6 PM cut-off:
If you specifically need the worker to run at 6:00 PM exactly (and no later), adjust the hour range to 9-18 instead of 9-17. That way, the last execution will be at 6:00 PM, and no runs will happen after that until the next weekday morning.
Don't forget timezone!
If your server uses a different timezone than your target work hours, add the timezone key to your configuration (like the commented line above) to ensure the schedule aligns with your local time.
This setup will perfectly meet your requirement: the worker runs every minute during weekday business hours, and stays idle on weekends.
内容的提问来源于stack exchange,提问作者rwehresmann

