Forums

Why sheduled task takes so long?

I am using this code for scheduled task:

import urllib.request
from datetime import date

day_num = date.today().weekday()

def db_update():
    """Download db"""
    #code here

def db_make():
    """process db"""
    #code here

if __name__ == "__main__":
    if day_num == 1:
        db_update()
    if day_num == 2:
        db_make()

And this is my log:

2017-11-09 06:31:30 -- Completed task, took 45.00 seconds, return code was 0.
2017-11-10 06:31:16 -- Completed task, took 40.00 seconds, return code was 0.
2017-11-11 06:31:25 -- Completed task, took 48.00 seconds, return code was 0.
2017-11-12 06:31:22 -- Completed task, took 52.00 seconds, return code was 0.
2017-11-13 06:31:22 -- Completed task, took 44.00 seconds, return code was 0.
2017-11-14 06:31:27 -- Completed task, took 44.00 seconds, return code was 0.
2017-11-15 06:35:07 -- Completed task, took 274.00 seconds, return code was 0.
2017-11-16 06:31:18 -- Completed task, took 43.00 seconds, return code was 0.
2017-11-17 06:31:38 -- Completed task, took 29.00 seconds, return code was 0.

I think the task should not take more than miliseconds except for day 1 and 2.

why the task takes so much time?

the task servers are under quite heavy load, so depending on the time of day, it can be quite slow to just start up a process. once the actual python interpreter is loaded along with all your dependencies, things should be back to slightly more normal speeds though. try adding some debug logging inside your actual code if you like?

Ok.

No problem. I just wanted to make sure that I am not blocking anything.

Thanks.