如何修复发送到未初始化实例的延迟任务?

2024-04-25 13:52:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我的googleappengine网站正在使用延迟任务来做很多额外的工作。有时,延迟任务的数量会导致创建一个新实例。发生这种情况时,委派给这个新实例的所有任务都会失败,因为它们在实例有机会初始化之前就被发送到那里。如果在任务进入之前已经启动了足够多的实例,则不会发生任何问题

下面是一个失败任务的示例:

Permanent failure attempting to execute task (/.../google/appengine/ext/deferred/deferred.py:327)
Traceback (most recent call last):
  File "/.../google/appengine/ext/deferred/deferred.py", line 318, in post
    self.run_from_request()
  File "/.../google/appengine/ext/deferred/deferred.py", line 313, in run_from_request
    run(self.request.body)
  File "/.../google/appengine/ext/deferred/deferred.py", line 153, in run
    raise PermanentTaskFailure(e)
PermanentTaskFailure: No module named django

有没有办法告诉延迟的系统等到实例完全初始化后再向其发送任务?因为这个问题我头发都掉光了


Tags: 实例runinfrompyselfrequestgoogle
1条回答
网友
1楼 · 发布于 2024-04-25 13:52:42

GAEwarmup requests的设计正是为了做到这一点:

Loading your app's code to a new instance can result in loading requests. Loading requests can result in increased request latency for your users, but you can avoid this latency using warmup requests. Warmup requests load your app's code into a new instance before any live requests reach that instance.

你只需要:

相关问题 更多 >