当启动处理程序完成时,如何显式停止 Google App Engine 动态后端?
我有一个后端在其启动处理程序中消耗一个队列。当队列耗尽时,启动处理程序将停止。我希望后端在启动处理程序完成时停止。我还有其他代码,如果将项目添加到此队列,则会向后端发送请求。这些请求仅用于让 GAE 启动后端,以便它可以开始使用队列。
我不希望后端处于启动处理程序已完成但后端保持空闲的状态。我希望它停止,以便对后端的下一个请求将导致 GAE 再次启动后端,从而再次调用启动处理程序并开始消耗队列。
我如何实现这个目标?
I have a backend that consumes a queue in its start handler. When the queue is exhausted the start handler will stop. I want the backend to stop when the start handler finishes. I have other code that will send a request to the backend if it adds an item to this queue. These requests merely serve to have GAE start the backend so that it can start consuming the queue.
I don't want the backend to ever be in a state where the start handler has finished but the backend remains idle. I want it to stop so that the next request to the backend will cause GAE to start the backend again thus invoking the start handler again and start consuming the queue.
How do I accomplish this goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
后端(当前)无法以编程方式启动和停止。不过,听起来您想要的是一个常规任务队列任务,其行为与所描述的完全一样。
Backends can't (currently) be started and stopped programmatically. It sounds like what you want, though, is a regular task queue task, which behaves exactly as described.
如果您将后端配置为动态后端,则后端将在处理您的“触发”请求后 15 分钟自动停止。如果您在接下来的 15 分钟内不再发送“触发启动”请求,后端将自动关闭。不幸的是,您仍然需要为至少 15 分钟的正常运行时间付费,即使后端在这 15 分钟内处于空闲状态。我正在做的正是您在我的应用程序中所做的事情 - 后端启动,开始从拉取队列中租赁任务,并在拉取队列为空时进入空闲状态。我每小时执行一次此操作,因此我最终每天要为 24/3 = 8 小时的后端正常运行时间付费。由于这低于 9 小时配额,所以我很高兴(目前)。
If you configure your backend as a Dynamic backend, then the backend will stop automatically 15 minutes after your "trigger" request is processed. If you don't send that "trigger-to-start" request again in the next 15 minutes, the backend will shutdown automatically. Unfortunately, you'll still have to pay for a minimum of 15 minutes of uptime, even though the backend is idle for those 15 minutes. I'm doing exactly what you're doing in my app - the backend starts, starts leasing tasks from a pull queue, and goes idle when the pull queue is empty. I do this once every hour, so I end up paying for 24/3 = 8 hours of backend uptime everyday. Since this is below the 9 hour quota, I'm happy (for now).