problem with start_time of the scheduler

57 views
Skip to first unread message

Martin Weissenboeck

unread,
Oct 15, 2016, 9:27:33 AM10/15/16
to web2py-users
It seems that the start_time parameter in a scheduler_task record does not work correctly.

For example:

I add a record to scheduler_task which should start the function "smsEmailAussenden" (means "send the email") at 16:00 

I expect the email to be sended at 16:00, but it starts immediately. At 14:45 all is done...

I use this code to add a new task. All names without a value are parameters of the function containing this statement. start_time != None

       tasknr = db.scheduler_task.insert(
            status='QUEUED',
            application_name='secure',
            task_name=task_name, 
            function_name='smsEmailAussenden',
            args = dumps([aussendungNr]),
            vars={},
            enabled=True,
            start_time=start_time or datetime.datetime.now(),
            stop_time=stop_time or (datetime.datetime.now()+timedelta(days=1)),
            repeats=1,
            retry_failed=1, 
            period=800, 
            timeout=200,            
        )

Some months ago this code worked without problems.
What has changed inside the scheduler?

913997
0=unlimited
-1=unlimited
seconds
Cron-like start_times between runs
seconds
update output every n sec: 0=never



Any ideas?
Regards, Martin

Dave S

unread,
Oct 15, 2016, 1:59:01 PM10/15/16
to web2py-users, mwei...@gmail.com


On Saturday, October 15, 2016 at 6:27:33 AM UTC-7, mweissen wrote:
It seems that the start_time parameter in a scheduler_task record does not work correctly.

For example:

I add a record to scheduler_task which should start the function "smsEmailAussenden" (means "send the email") at 16:00 

I expect the email to be sended at 16:00, but it starts immediately. At 14:45 all is done...

I use this code to add a new task. All names without a value are parameters of the function containing this statement. start_time != None

       tasknr = db.scheduler_task.insert(
            status='QUEUED',
            application_name='secure',
            task_name=task_name, 
            function_name='smsEmailAussenden',
            args = dumps([aussendungNr]),
            vars={},
            enabled=True,
            start_time=start_time or datetime.datetime.now(),

So if start_time hasn't been set anywhere in your queuing code, it runs now.
The start_time value on the right side is a (local) variable, not the previous value of the parameter.

 
            stop_time=stop_time or (datetime.datetime.now()+timedelta(days=1)),
            repeats=1,
            retry_failed=1, 
            period=800, 
            timeout=200,            
        )

Some months ago this code worked without problems.
What has changed inside the scheduler?


The scheduler has been stable across a couple of releases, I think.  My once-a-day code has been working very well for several months.

/dps


 

Martin Weissenboeck

unread,
Oct 16, 2016, 2:30:23 AM10/16/16
to Dave S, web2py-users
Thank you, but start_time has a value.
start_time is a paramter of the surrounding function.
I have tested it with 
task_name = task_name + str(start_time)
and therefore I have written start_time != None
--
Mit freundlichen Grüßen / With kind regards
Martin Weissenböck
Gregor-Mendel-Str. 37, 1190 Wien
Austria / European Union

Niphlod

unread,
Oct 17, 2016, 3:08:09 PM10/17/16
to web2py-users, snide...@gmail.com, mwei...@gmail.com
the bug has already been fixed in trunk. 
You can copy/paste the scheduler.py file from master if you want it solved, or either pass next_run_time equal to start_time to make things work the way they were.

Niphlod

unread,
Oct 17, 2016, 3:11:14 PM10/17/16
to web2py-users, snide...@gmail.com, mwei...@gmail.com
BTW: please start adapting your code to use mysched.queue_task(....) instead of db.scheduler_task.insert(...) . 
Next releases could change the format of the scheduler_task table and only the queue_task method is the supported one (i.e. will handle eventual corner-cases that won't be possible using db.scheduler_task.insert(....)) 

Martin Weissenboeck

unread,
Oct 19, 2016, 1:23:31 AM10/19/16
to Niphlod, web2py-users, Dave S
It works perfect - thank you!

Martin Weissenboeck

unread,
Oct 19, 2016, 1:27:51 PM10/19/16
to Niphlod, web2py-users, Dave S
2016-10-17 21:11 GMT+02:00 Niphlod <nip...@gmail.com>:
BTW: please start adapting your code to use mysched.queue_task(....) instead of db.scheduler_task.insert(...) . 
Next releases could change the format of the scheduler_task table and only the queue_task method is the supported one (i.e. will handle eventual corner-cases that won't be possible using db.scheduler_task.insert(....)) 


Thank you again for this hint. ​I have changed my program.
If somebody is interested (changes are marked red):

This is the old code:

      tasknr = db.scheduler_task.insert(
            status='QUEUED',
            application_name='secure',
            task_name=task_name, 
            function_name='smsEmailAussenden',
            args = dumps([aussendungNr]),
            vars={},

            enabled=True,
            start_time=start_time or datetime.datetime.now(), 
            stop_time=stop_time or (datetime.datetime.now()+timedelta(days=1)),
            repeats=1,
            retry_failed=1, 
            period=800, 
            timeout=200,            
        )

I have changed it to:
        
        start_time1 = start_time or datetime.datetime.now()
        
        scheduler.queue_task(
            smsEmailAussenden,
            application_name='secure',
            task_name=task_name,
            pargs=[aussendungNr],
            pvars={},
            enabled=True,
            start_time=start_time1,
            next_run_time=start_time1,
            stop_time=stop_time or (start_time1 + timedelta(days=1)),




Reply all
Reply to author
Forward
0 new messages