Run custom code upon error ticket issuance?

46 views
Skip to first unread message

Francisco Ribeiro

unread,
Feb 15, 2018, 11:41:53 AM2/15/18
to web2py-users
Hi all,

I have created an event viewer web console that uses websockets to keep itself up to date. 
I wanted error tickets to show up in here as well, so once a ticket is issued it would execute my custom code that keeps my event viewer up to date with a link to the ticket itself.
Ideally, the solution should not involve changing web2py source code since I could lose my changes once I upgrade web2py but if it comes to that, i'm OK with it.

Thanks in advance.

Kind regards,
Francisco

Leonel Câmara

unread,
Feb 15, 2018, 12:43:58 PM2/15/18
to web2py-users
I'd say the easiest way would be to use routes_on_error, you can put a controller function of your application there.

On you web2py directory you would make a routes.py with

routes_onerror
= [
 
('myapp/*', '/myapp/default/error')
]



Then on default.py you could have a function like this:

def error():
    code
= request.vars.code
    ticket
= request.vars.ticket
   
if code == '500':
       
# do your websocket stuff
   
return locals()  # Make sure you have a error.html for the visitor to get a nice error page



Francisco Ribeiro

unread,
Feb 15, 2018, 3:25:20 PM2/15/18
to web2py-users
That is useful but is it really equivalent to error ticket issuance i.e. do all tickets we see as error tickets hit the routes_onerror?  What if the error is triggered by a scheduled task running in the background?

Thanks

Leonel Câmara

unread,
Feb 15, 2018, 6:19:01 PM2/15/18
to web2py-users
No this doesn't work for scheduler tasks. Note that scheduler task that have errors do not produce an error ticket anyway. For scheduler tasks I would inherit from scheduler and override set_worker_status to also do some other action when it's setting it to FAILED.
Reply all
Reply to author
Forward
0 new messages