jeudi 24 juin 2021

How to add a component of randomness to a schedule

I am trying to schedule a job to run every 3 minutes on average, with a component of randomness between +/- 30 seconds. So the next job runs anywhere between 2mins 30secs - 3mins 30secs later.

This code works nicely for exactly 3 minutes, but I can't think of a way to introduce the 30 secs of randomness:

import schedule
def job:
   print('hi')

schedule.every(3).minutes.do(job)



Aucun commentaire:

Enregistrer un commentaire