why periodic python sched function repeats itself every second instead of repeat every other n minutes?

28 Views Asked by At

I want my script to run every n minutes starting from NOT NOW, but rather starting from the time I specified. When I do:

def periodic(scheduler, interval, action, actionargs=()):
     schedule_data_update.enterabs(interval, 1, periodic,
                (scheduler, interval, action, actionargs))
     action(*actionargs)
     logging.info('Running scheduled repeated updates') 

periodic(schedule_data_update, 120.0 , data_runner)

Above 120.0 is 2 minutes, when i am running it - it is running data_runner() every 2 minutes starting from now. However, when i replace that 120.0 with some other time and run it

repeater = int(update['update_interval']) + 120.0 
periodic(schedule_data_update, repeater  , data_runner)

where

int(update['update_interval']) == 1658746706.0

and

int(update['update_interval']) + 120.0 == 1658746826.0

it's running at the exact time I want it to run, but it is looping without stopping

Here are my loggings:

2022-07-25 16:56:22,265:INFO:Running scheduled repeated updates
2022-07-25 16:56:23,897:INFO:Running scheduled repeated updates
2022-07-25 16:56:25,341:INFO:Running scheduled repeated updates
2022-07-25 16:56:26,971:INFO:Running scheduled repeated updates
......
a lot more... (every other second)

My desired end result is:

2022-07-25 16:56:22,265:INFO:Running scheduled repeated updates
2022-07-25 16:58:22,265:INFO:Running scheduled repeated updates
#EVERY 2 MINUTES starting the time i specified above (repeater)

NOTE: I am required to use SCHED library and not anything else

0

There are 0 best solutions below