NP. I got another way to catch failed mail/task.
*#models/scheduler.py* def send_mail(to, subject, message, cc=None, bcc=None, attachments=None): """ This module is called by scheduler. mail is queued by scheduler. """ if cc is None: cc = [] if bcc is None: bcc = [] if attachments is None: attachments = [] #sending mail print W2P_TASK result= mail.send(to=to, cc=cc, bcc=bcc, subject=subject, message=message, attachments=attachments) if not result: raise Exception("Mail sent failed") This is working for me. It will change current task status to "FAILED". I can easily find which mails sent failed due to mail.send errors On Thu, Aug 28, 2014 at 3:52 PM, Niphlod <niph...@gmail.com> wrote: > no. > > > On Thursday, August 28, 2014 10:26:42 AM UTC+2, Prasad Muley wrote: > >> Okay. >> I am using 2.3 . I can't upgrade it because Company decided to use 2.3 >> only. >> Is there anyway to access current task id in 2.3? >> >> >> >> On Thu, Aug 28, 2014 at 1:47 PM, Niphlod <nip...@gmail.com> wrote: >> >>> what version are you using ?! W2P_TASK is available from 2.4.1. >>> >>> >>> On Thursday, August 28, 2014 9:30:28 AM UTC+2, Prasad Muley wrote: >>> >>>> Hi Niphlod, >>>> I need to get current task's id. I saw your sample scheduler >>>> example on niphlod_w2p_scheduler_tests >>>> <https://github.com/niphlod/w2p_scheduler_tests/blob/master/models/scheduler.py> >>>> I did it in same way but got error. >>>> >>>> >>>> >>>> *#models/scheduler.py* >>>> def send_mail(to, subject, message, cc=None, bcc=None, >>>> attachments=None): >>>> """ >>>> This module is called by scheduler. >>>> mail is queued by scheduler. >>>> """ >>>> if cc is None: >>>> cc = [] >>>> if bcc is None: >>>> bcc = [] >>>> if attachments is None: >>>> attachments = [] >>>> #sending mail >>>> print W2P_TASK >>>> result= mail.send(to=to, cc=cc, bcc=bcc, >>>> subject=subject, message=message, >>>> attachments=attachments) >>>> >>>> #if not result: >>>> # print "FAILED: Task [%d]" % W2P_TASK.id >>>> ### update tasks' status >>>> >>>> >>>> from gluon.scheduler import Scheduler >>>> mail_scheduler = Scheduler(db, migrate=False) >>>> >>>> >>>> I got following error >>>> >>>> DEBUG:web2py.scheduler: new task report: FAILED >>>> DEBUG:web2py.scheduler: traceback: Traceback (most recent call last): >>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/scheduler.py", line 229, >>>> in executor >>>> result = dumps(_function(*args, **vars)) >>>> File "applications/lcm/models/scheduler.py", line 16, in send_mail >>>> print W2P_TASK >>>> NameError: global name 'W2P_TASK' is not defined >>>> >>>> >>>> >>>> if mail.send() fails due to some issue [for eg wrong password, port >>>> etc] >>>> Still web2py scheduler mark current task as COMPLETED. >>>> >>>> That's why I want to check mail.send's result. >>>> If result is False then I've to update current task's status as Failed. >>>> How do I get id of current task? >>>> >>>> Thanks in advance. >>>> >>>> >>>> On Tue, Aug 26, 2014 at 3:46 PM, Niphlod <nip...@gmail.com> wrote: >>>> >>>>> I'd strongly advise you to read the section on the book about >>>>> migrations and fixing broke migrations. >>>>> If you're starting now with the scheduler, please do the following: >>>>> - delete all databases/*_scheduler_*.table files >>>>> - delete scheduler_worker, scheduler_tasks, scheduler_run table from >>>>> your backend MANUALLY >>>>> - use Scheduler(db, ...., migrate=True) >>>>> - open appadmin >>>>> - reset Scheduler(db, ...., migrate=False) >>>>> >>>>> >>>>> On Tuesday, August 26, 2014 11:18:25 AM UTC+2, Prasad Muley wrote: >>>>> >>>>>> Hi, >>>>>> I tried to access db.scheduler_run table but it is giving me >>>>>> following error in web2py shell and app admin UI. >>>>>> >>>>>> *OperationalError: (1054, "Unknown column >>>>>> 'scheduler_run.scheduler_task' in 'field list'")* >>>>>> >>>>>> >>>>>> On Tue, Aug 26, 2014 at 1:04 PM, Niphlod <nip...@gmail.com> wrote: >>>>>> >>>>>>> there's yet a scheduler_task table in the database. Fix migrations >>>>>>> in the usual way, or set Scheduler(db,....,migrate=False) to avoid >>>>>>> the error. >>>>>>> >>>>>>> >>>>>>> On Tuesday, August 26, 2014 8:58:06 AM UTC+2, Prasad Muley wrote: >>>>>>>> >>>>>>>> Hi, >>>>>>>> I've web2py 2.3 version. I tried to use scheduler for mail >>>>>>>> sending. >>>>>>>> I got this error while creating a worker for scheduler >>>>>>>> >>>>>>>> $ python web2py.py -K send_mail_app >>>>>>>> >>>>>>>> [12:07:02] >>>>>>>> web2py Web Framework >>>>>>>> Created by Massimo Di Pierro, Copyright 2007-2014 >>>>>>>> Version 2.3.2 (2012-12-17 15:03:30) stable >>>>>>>> Database drivers available: SQLite(sqlite2), SQLite(sqlite3), >>>>>>>> MySQL(pymysql), MySQL(MySQLdb), PostgreSQL(psycopg2), >>>>>>>> PostgreSQL(pg8000), >>>>>>>> MSSQL(pyodbc), DB2(pyodbc), Teradata(pyodbc), IMAP(imaplib) >>>>>>>> starting single-scheduler for "send_mail_app"... >>>>>>>> Traceback (most recent call last): >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/restricted.py", line >>>>>>>> 212, in restricted >>>>>>>> exec ccode in environment >>>>>>>> File "applications/send_mail_app/models/scheduler.py", line 2, >>>>>>>> in <module> >>>>>>>> mail_scheduler = Scheduler(db) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/scheduler.py", line >>>>>>>> 449, in __init__ >>>>>>>> self.define_tables(db, migrate=migrate) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/scheduler.py", line >>>>>>>> 501, in define_tables >>>>>>>> migrate=migrate, format='%(task_name)s') >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 7186, in >>>>>>>> define_table >>>>>>>> table = self.lazy_define_table(tablename,*fields,**args) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 7222, in >>>>>>>> lazy_define_table >>>>>>>> polymodel=polymodel) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 935, in >>>>>>>> create_table >>>>>>>> self.create_sequence_and_triggers(query,table) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 1694, in >>>>>>>> create_sequence_and_triggers >>>>>>>> self.execute(query) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 1709, in >>>>>>>> execute >>>>>>>> return self.log_execute(*a, **b) >>>>>>>> File "/home/prasad/Rootpy/web2py 2.3/gluon/dal.py", line 1703, in >>>>>>>> log_execute >>>>>>>> ret = self.cursor.execute(*a, **b) >>>>>>>> File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", >>>>>>>> line 201, in execute >>>>>>>> self.errorhandler(self, exc, value) >>>>>>>> File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", >>>>>>>> line 36, in defaulterrorhandler >>>>>>>> raise errorclass, errorvalue >>>>>>>> OperationalError: (1050, "Table 'scheduler_task' already exists") >>>>>>>> >>>>>>>> I've followed following instructions. >>>>>>>> >>>>>>>> *1) Created a file models/scheduler.py* >>>>>>>> >>>>>>>> #code from scheduler.py file >>>>>>>> from gluon.scheduler import Scheduler >>>>>>>> mail_scheduler = Scheduler(db) >>>>>>>> >>>>>>>> >>>>>>>> def send_mail(to, subject, message, cc=None, bcc=None, >>>>>>>> attachments=None): >>>>>>>> """ >>>>>>>> This module is called by scheduler. >>>>>>>> You can check scheduler_task table and scheduler.task_status >>>>>>>> table >>>>>>>> """ >>>>>>>> if cc is None: >>>>>>>> cc = [] >>>>>>>> if bcc is None: >>>>>>>> bcc = [] >>>>>>>> if attachments is None: >>>>>>>> attachments = [] >>>>>>>> #sending mail >>>>>>>> mail.send(to=to, cc=cc, bcc=bcc, >>>>>>>> subject=subject, message=message, >>>>>>>> attachments=attachments) >>>>>>>> >>>>>>>> *2) Called send_mail module in an external script.* >>>>>>>> (scripts/send_mails.py) >>>>>>>> >>>>>>>> #extra code here >>>>>>>> task = mail_scheduler.queue_task('send_mail', >>>>>>>> pvars={'to': email, >>>>>>>> 'subject': >>>>>>>> subject, >>>>>>>> 'message': >>>>>>>> html_email}, >>>>>>>> >>>>>>>> start_time=datetime.datetime.now()) >>>>>>>> print task >>>>>>>> >>>>>>>> >>>>>>>> *3) Created a worker and got above error* >>>>>>>> >>>>>>>> >>>>>>>> Am I missing some steps? >>>>>>>> >>>>>>> -- >>>>>>> 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 a topic in >>>>>>> the Google Groups "web2py-users" group. >>>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/to >>>>>>> pic/web2py/gx5o0vAGXQQ/unsubscribe. >>>>>>> To unsubscribe from this group and all its topics, send an email >>>>>>> to web2py+un...@googlegroups.com. >>>>>>> >>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Thanks and Regards >>>>>> Prasad M. Muley >>>>>> Programmer at One Delta Synergies Pvt Ltd. | PICT 2013 >>>>>> >>>>>> “Pretty much everything on the web uses those two things: *C* and >>>>>> *UNIX*,” - Dennis Ritchie >>>>>> *http://www.cs.bell-labs.com/who/dmr/* >>>>>> <http://www.cs.bell-labs.com/who/dmr/> >>>>>> >>>>> -- >>>>> 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 a topic in the >>>>> Google Groups "web2py-users" group. >>>>> To unsubscribe from this topic, visit https://groups.google.com/d/to >>>>> pic/web2py/gx5o0vAGXQQ/unsubscribe. >>>>> To unsubscribe from this group and all its topics, send an email to >>>>> web2py+un...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> Thanks and Regards >>>> Prasad M. Muley >>>> Programmer at One Delta Synergies Pvt Ltd. | PICT 2013 >>>> >>>> “Pretty much everything on the web uses those two things: *C* and >>>> *UNIX*,” - Dennis Ritchie >>>> *http://www.cs.bell-labs.com/who/dmr/* >>>> <http://www.cs.bell-labs.com/who/dmr/> >>>> >>> -- >>> 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 a topic in the >>> Google Groups "web2py-users" group. >>> To unsubscribe from this topic, visit https://groups.google.com/d/ >>> topic/web2py/gx5o0vAGXQQ/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> web2py+un...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Thanks and Regards >> Prasad M. Muley >> Programmer at One Delta Synergies Pvt Ltd. | PICT 2013 >> >> “Pretty much everything on the web uses those two things: *C* and *UNIX*,” >> - Dennis Ritchie >> *http://www.cs.bell-labs.com/who/dmr/* >> <http://www.cs.bell-labs.com/who/dmr/> >> > -- > 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/gx5o0vAGXQQ/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Thanks and Regards Prasad M. Muley Programmer at One Delta Synergies Pvt Ltd. | PICT 2013 “Pretty much everything on the web uses those two things: *C* and *UNIX*,” - Dennis Ritchie *http://www.cs.bell-labs.com/who/dmr/* <http://www.cs.bell-labs.com/who/dmr/> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.