Visibly & permanently failing GAE tasks
The App Engine taskqueues ensure that tasks are retried if they return a status code outside of 2xx range, which obviously includes stray exceptions. This is fine for occasional failures such as timeouts, but in case of permanent failures - when task cannot complete successfully regardless of how many time it's retried - it causes unnecessary load. Of course one could return 2xx in such case but this would not be registered as an errornous request by GAE and not shown in the 'Errors' table on Admin Console dashboard.
Hence I'm asking: is there a way to fail a task in such fashion that it i开发者_Go百科s:
- not retried (permanent failure)
- visible in the Admin Console as errornous request
All you have to do to make a request show up in the errors tab of the admin console is to log at least one message at level ERROR
or higher. Simply log said message, then return a 200 status code to ensure your task is not re-enqueued.
If all you want to do is stop retrying after a certain number of retries, you can configure that.
There's a bit of a catch 22 here. You want to not retry a task that fails in some particular way. But other than HTTP response codes, how is GAE to know? "Yes, I failed, but that's O.K." or "Yes, I failed, and I forever will" aren't possible to communicate given the HTTP response codes available (other than maybe "501 Not Implemented", which means something else). The closest you can gets is a 2xx response, which some failure scenarios will preclude.
There's no facility for examining task stack traces, but if there were, determining that a particular stack trace means that a failure condition is permanent is going to be rather difficult. PhD dissertations might be involved.
I think this one comes down to testing and vigilance.
精彩评论