Search code examples
pythoncron

Cron job in python every x hours - 1 minute


I would like to create a cron job that triggers at 23h59, then 3h59, 7h59, 11h59...

My solution

scheduler.add_job(
    func=myfunc,
    trigger="cron",
    day='*',
    hour="*/4",
    minute=59,
    second=0,
)

works but triggers every time one hour too late: 00.59, 4.59... Any solution please?


Solution

  • You are using APScheduler. You can do

    scheduler.add_job(
        func=myfunc,
        trigger="cron",
        day='*',
        hour="3-23/4",
        minute=59,
        second=0,
    )
    

    Check the scheduled times here