简体   繁体   中英

How can I automatically retry a task executed on a GAE backend?

Currently I am running a task on a Java backend using cron.

<cron>
   <url>/admin/stats?action=dailyStats</url>
   <description>Send daily statistics</description>
   <schedule>every day 16:50</schedule>
   <target>backends1</target>
   <timezone>Europe/Madrid</timezone>
</cron>

The backends are configured with 2 dynamic instances:

<backends>
    <backend name="backends1">
     <class>B2</class>
 <instances>2</instances>
     <options>
      <dynamic>true</dynamic>
     </options>
    </backend>
</backends>

Usually it works fine, but some times the instance executing the task just dies without any further notice so I would need it to be retried automatically after this failure.

You need add code at at the beginning of yours task code for schedule next launch of task (backup task) with an offset of several second (or minutes, depending on how long task is executed) - for failure execution. And at the end of you task code add code to delete this backup task.

If the task is going to die then perform again. Or if task is going to finished with success then backup task will be deleted.

If you need retries on GAE you should use task queues. A task queue can trigger a task and will complete only if the triggered task returns successful HTTP response, like 200. Otherwise it will retry the task. Additionally you can configure several queue processing parameters. It can be used to trigger processing both in backends and frontends.

For more details see https://developers.google.com/appengine/docs/python/taskqueue/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM