what's the best way to use scheduler for a daily task?

53 views
Skip to first unread message

Rudy

unread,
Jul 21, 2017, 9:27:50 AM7/21/17
to web...@googlegroups.com
I want to clean up a table daily using schedule at midnight, I don't want scheduler to poll too often to waste unnecessary resource. how should I do it?
1) give heartbeat a large number in scheduler = Scheduler(db_sch, heartbeat=7200)?
2) if len(db_sch().select(db_sch.scheduler_task.ALL)) == 0:
         scheduler.queue_task(clear_curr_exch_cache, period=86400, repeats=0)
3) create a cron job in linux to start the scheduler (python web2py.py -K myapp -p 8002), another cron job to kill the process after a fixed period of time
4) create a cron job to start the scheduler, call scheduler.terminate() after db.commit() before return in the task action
5) combination of above

Another question: how to i associate tasks to a specific group? I seem to miss this in the doc

Thank you!

Dave S

unread,
Jul 21, 2017, 3:29:47 PM7/21/17
to web2py-users
On Friday, July 21, 2017 at 6:27:50 AM UTC-7, Rudy wrote:
I want to clean up a table daily using schedule at midnight, I don't want scheduler to poll too often to waste unnecessary resource. how should I do it?

I'm pretty sure Niphlod will say (and has said), "Why bother?" -- the scheduler resources are pretty minimal when a task isn't running.

Just about everything except the heartbeat change seems like it will consume as much resources.

By the way, the 2.15.x builds had the "cron-like" queue option, which I'm looking forward to trying.
 
1) give heartbeat a large number in scheduler = Scheduler(db_sch, heartbeat=7200)?
2) if len(db_sch().select(db_sch.scheduler_task.ALL)) == 0:
         scheduler.queue_task(clear_curr_exch_cache, period=86400, repeats=0)
3) create a cron job in linux to start the scheduler (python web2py.py -K myapp -p 8002), another cron job to kill the process after a fixed period of time
4) create a cron job to start the scheduler, call scheduler.terminate() after db.commit() before return in the task action
5) combination of above

Another question: how to i associate tasks to a specific group? I seem to miss this in the doc


I'd take a look at the scheduler tests -- Niphlod's default.py controller at 
<URL: https://github.com/niphlod/w2p_scheduler_tests>
seems to have the detailed explanation around lines 600ff

/dps

Thank you!

Dave S

unread,
Jul 21, 2017, 4:26:52 PM7/21/17
to web2py-users

On the other hand, if you only have a single task, groups seems to be unnecessary.

/dps

Reply all
Reply to author
Forward
0 new messages