On Saturday, 14 May 2016 08:38:57 UTC-1, Steve Joe wrote:
>
> how to write a scheduler function that will send me an email with subject 
> "hello" every night at 12 am?
>

Yep,
1-Launch the scheduler on a command prompt
run cmd.exe or any terminal on your computer and type
python web2py.py -K myapp

2-Declare the scheduler on your models.
from gluon.scheduler import Scheduler
sched = Scheduler(db)

3.-Create a mailing function that will send the email in one of your models.

4.- Launch the scheduled task. Open another command prompt and type:

python web2py.py -a <your_password> -S <your_appname> -M

The scheduler should be avalaible as "sched". Start the task
task = sched.queue_task(my_mailing_function, .... parameters here according 
to the signature)
db.commit()

and close the console. Look the table db.scheduler_task in your database to 
confirm your task is running.

Scheduler signature:

scheduler.queue_task(
 function, 
 pargs=[], 
 pvars={}, 
 start_time=now, #datetime
 stop_time = None, #datetime
 timeout = 60, #seconds
 prevent_drift=False, 
 period=60, #seconds
 immediate=False, 
 repeats = 1 )

Yep, thats it, if it doesnt work you could use sched.queue_task within a 
controller but you will have to check if the task is already declared or not.
Also the scheduler adds some overhead to the database, i dont like it, but its 
ok if it works for you.





-- 
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.

Reply via email to