On Tuesday, October 25, 2016 at 5:12:09 PM UTC-7, 黄祥 wrote:
>
> learn from niphlod github about web2py scheduler test, there are some
> question about it:
> 1. is it neccessary to delete all data in table scheduler_worker,
> scheduler_task, scheduler_run before queue the task?
> *e.g.*
> def clear_all():
> swstatus = db(db.scheduler_worker.id > 0).delete()
> srstatus = db(db.scheduler_run.id > 0).delete()
> ststatus = db(db.scheduler_task.id > 0).delete()
>
I'm pretty sure that's just a testing artifact: always start tests with a
known set of pre-conditions .
2. let say i have 2 or more scheduler function is it better to group all
> the 2 in 1 function or separate it? what is recommended or best practice
> for this?
> *e.g. group all the 2*
> def queue_task():
> start_now = datetime.datetime.now()
> scheduler.queue_task('task_0', prevent_drift = True, start_time =
> start_now,
> next_run_time = start_now, stop_time = (start_now +
> datetime.timedelta(days = 1) ),
> repeats = 0, retry_failed = 1, period = 60, timeout = 86400
> )
> scheduler.queue_task('task_1', prevent_drift = True, start_time =
> start_now,
> next_run_time = start_now, stop_time = (start_now +
> datetime.timedelta(days = 1) ),
> repeats = 0, retry_failed = 1, period = 86400, timeout = 86400
> )
> response.js = "jQuery('#scheduler_status').get(0).reload()"
> response.flash = T("Task Queued")
>
> *e.g. separate queue task*
> def queue_task_0():
> start_now = datetime.datetime.now()
> scheduler.queue_task('task_0', prevent_drift = True, start_time =
> start_now,
> next_run_time = start_now, stop_time = (start_now +
> datetime.timedelta(days = 1) ),
> repeats = 0, retry_failed = 1, period = 60, timeout = 86400
> )
> response.js = "jQuery('#scheduler_status').get(0).reload()"
> response.flash = T("Task Queued")
>
> def queue_task_1():
> start_now = datetime.datetime.now()
> scheduler.queue_task('task_1', prevent_drift = True, start_time =
> start_now,
> next_run_time = start_now, stop_time = (start_now +
> datetime.timedelta(days = 1) ),
> repeats = 0, retry_failed = 1, period = 86400, timeout = 86400
> )
> response.js = "jQuery('#scheduler_status').get(0).reload()"
> response.flash = T("Task Queued")
>
>
I'm not sure there is a general answer to question 2. Your workflow or the
nature of the queued tasks may suggest one or other. If one task has a
dependency on the other, check out Niphlod's Job interface
<URL:https://groups.google.com/d/msg/web2py/oznIjHcTLPo/Ip-ehzA5CAAJ>
3. i want to have the scheduler run at the day 28 of the month, what is
> recommended to use next_run_time or period to achieve it?
> *e.g.*
> start_eom = '%s-%s-28 00:00:00' % (request.now.year, request.now.month)
> start_eom_date = datetime.datetime.strptime(start_eom, '%Y-%m-%d %H:%M:%S')
>
>
Since months vary in length, I'd use next_run_time. The next month is the
current month plus 1, wrap 13 to 1. (I don't think you need a timedelta
for this, but mod 12 is a bit fussy since Python uses 1 for January.)
/dps
thanks and best regards,
> stifan
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.