1

I have a Google App Engine servlet that is cron configured to run once a week. Since it will take more than 1 minute of execution time, it launches a task (i.e. another servlet task/clear) on the application's default push task queue.

Now what I'm observing is this: if the task causes an exception (e.g. NullPointerException inside its second servlet), this gets translated into HTTP status 500 (i.e. HttpURLConnection.HTTP_INTERNAL_ERROR) and Google App Engine apparently reacts by immediately relaunching the same task again. It announces this by printing:

Web hook at http://127.0.0.1:8888/task/clear returned status code 500.  Rescheduling..

I can see how this can sometimes be a feature, but in my scenario it's inappropriate. Can I request that Google App Engine should not do such automatic rescheduling, or am I expected to use other status codes to indicate error conditions that would not cause rescheduling by its rules? Or is this something that happens only on the dev. server?

BTW, I am currently also running other tasks (with different frequencies) on the same task queue, so throttling reschedules on the level of task queue configuration would be inconvenient (so I hope there is another/better option too.)

Community
  • 1
  • 1
Drux
  • 11,992
  • 13
  • 66
  • 116

2 Answers2

1

As per https://developers.google.com/appengine/docs/java/taskqueue/overview-push#Java_Task_execution - the task must return a response code between 200 and 299.

You can either return the correct value, set the taskRetryLimit in RetryOptions or check the header X-AppEngine-TaskExecutionCount when task launches to check how many times it has been launched and act accordingly.

theadam
  • 3,961
  • 4
  • 25
  • 41
  • +1 `X-AppEngine-TaskExecutionCount` will allows me to do an extra safety check inside the servlet. – Drux Jan 10 '14 at 07:54
0

I think I've found a solution: in the Java API, there is a method RetryOptions#taskRetryLimit, which serves my case.

Drux
  • 11,992
  • 13
  • 66
  • 116