schedule icon indicating copy to clipboard operation
schedule copied to clipboard

How to run on ecery xth Minute

Open biswaKL opened this issue 5 years ago • 3 comments

Hi, i want to run my code on every 5th minute like: 00:05, 00:10, 00:15, 00:20...

But now when i am defining like: schedule.every(5).minutes.do() it runs in every 5 min interval of starting the code..!!!

Something like */5 * * * * in cron..!! is it possible??

biswaKL avatar Mar 06 '19 21:03 biswaKL

It may be clunky, but have you looked at using .at?

you would have to use it several times but you could do schedule.every().hour.at(':05').do() schedule.every().hour.at(':10').do() schedule.every().hour.at(':15').do()

mjester93 avatar Mar 09 '19 15:03 mjester93

It would be sweet if at accepted an array. schedule.every().hour.at([':05',':10',..,':55']) Or, it just looked at @args and scheduled them all

kutenai avatar Mar 20 '19 22:03 kutenai

I created a simple snippet for this in case anyone is interested

def schedule_every(f, *, minute=5):
    """
    Creates a schedule similar to cron
        */5 * * * *
    """
    for i in range(minute, 60, minute):
        schedule.every().hour.at(f":{i:02d}").do(f)
        
        
schedule_every(job, minute=5)

yujinyuz avatar May 15 '23 14:05 yujinyuz