scheduler.add_job(func, IntervalTrigger(minutes=random.randint(1, 10), timezone="Europe/Rome"))The point I was trying to make is that what you're doing here is
calling random.randint(1, 10) once and then constructing an
IntervalTrigger using the result.
You seem to be under the impression that your code passes a
function that generates random integers between 1 and 10 and calls
that function every time it needs to calculate the next run time.
That is not how this works. Even if you did pass such a function
to IntervalTrigger (which you didn't), it would not work because
IntervalTrigger assumes that "minutes" is a simple numeric value,
and not a function.
To do what you wanted to achieve, you could create a custom trigger class that creates a timedelta with a randomized "minutes" value and uses that to construct the next fire time.
It might also be possible to use a plain IntervalTrigger with a
sufficiently large "jitter" value to achieve the same effect.
What do you mean ?
I want that the job will be rescheduled every time at a random value between 1 and 10.So, if I have this code it will be done ?
scheduler.add_job(func, IntervalTrigger(minutes=random.randint(1, 10), timezone="Europe/Rome"))
Il giorno mar 5 mag 2020 alle ore 09:43 Alex Grönholm <alex.g...@nextday.fi> ha scritto:
No. How do you suppose this is any different from:
x = random.randint(1, 10)
scheduler.add_job(func, IntervalTrigger(minutes=x, timezone="Europe/Rome"))
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/df4731d3-ddb0-4710-b429-c173d3df46a9%40googlegroups.com.
--
Giulio Coa.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/e0b1e45d-f2c0-5ba9-39e2-283f8a728d88%40nextday.fi.
Maybe you should start by showing what you have.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/CAGYrDHyipiRHQz4Au-N19%3DmTZFy66odqV_kY8yw4gxYourUm7w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/b82f4a9d-7a4e-be94-c1bc-5d3d31905937%40nextday.fi.
You need to override the get_next_fire_time() method. Generate
the random value there and use the timedelta class to add that to
the previous fire time. Look at the existing code for clues on how
it works.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/CAGYrDHxCTWzUZEU6_KbZPXomZEoF-fTyXfWbh7REqW4rfAXmrw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/51a86e47-a8f4-7427-977b-12194a46a864%40nextday.fi.
Sorry, I thought you didn't need more help.
Your code still needs to handle the case where previous_fire_time
is None. I suggest that you look at the original code for examples
on how to handle that.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/CAGYrDHz6QbA%3Dp6Kwrx-uoC_fWSKEr5aqGZcJW%2BCkSt1O0FWJcQ%40mail.gmail.com.