>
> Here is the summary of what I came up with, if anyone has similar
> situation.
>
modules/long_task.py:
def nwm_send_email(mailer,*args,**kwargs):
"""Send an email using the supplied dict args.
This function is called by the scheduler"""
args = args[1] # the first element is (), the second is the dict. Don't
know why. kwargs was empty
email_addr = args['email_addr']
s = args['subject']
m = args['message']
if mailer is None:
raise "mailer must not be None"
logging.info("sending mail...")
mailer.send(to=[email_addr],
subject = s,
message = m)
logging.info("finished sending mail...")
return 200 # or just return True
models/schedule.py:
from long_task import nwm_send_email
def nwm_task_send_email(*pvars, **kwargs):
"""use a springboard function so we can pass the global"""
return nwm_send_email(mail, pvars,kwargs)
modules/reporter.py: /// this one is called by the periodic scheduler
def longop(scheduler):
vars = {'email_addr': '[email protected]', 'subject': 'a test message',
'message': 'this is the body !'}
rtn = scheduler.queue_task('nwm_task_send_email' , task_name="long_email",
immediate=True, pvars=vars )
if rtn['id'] is None:
logging.error('error inserting task to DB: ' + str(rtn))
(thanks, Niphlod!)
Noam C.
--
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.