gpt4 book ai didi

Python App Engine 后端为 cron 工作,但如果我直接点击 url 则不会

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:49 25 4
gpt4 key购买 nike

我们有一个脚本需要一些时间来执行。我们已经安排了一个 cron 作业并使用后端来运行该作业。

这是 cron 的样子:
url: /cron/my_job_name<br/>
target: mybackend<br/>
schedule: every 30 minutes from 06:00 to 12:00

cron 作业按预期正确运行。但是当我点击网址时: https://myappname.googleplex.com/cron/my_job_name当作业运行超过 60 秒时,我收到“DeadlineExceededError”。

出于测试目的,我需要能够直接访问 url。我不想每次都更改 cron 计划进行测试。

有没有办法通过点击 url 来运行后端?

添加我的 app.yaml 和 backends.yaml

app.yaml
url: /cron/my_job_name<br/>
script: path/my_job_name.py<br/>
login: admin

后端.yaml
name: mybackend<br/>
class: B8<br/>
instances: 1<br/>
options: dynamic

最佳答案

听起来好像您在点击 URL 时实际上并没有调用后端实例来处理它。

来自docs :

A backend instance can be targeted with HTTP requests to http://[instance].[backend_name].[your_app_id].appspot.com, or at your application's custom domain. If you target a backend without targeting an instance using http://[backend_name].[your_app_id].appspot.com, App Engine selects the first available instance of the backend.

The Backends API provides functions to retrieve the address of a backend or instance. This allows application versions to target backends with requests, for a backend to target another backend, or for one instance of a backend to target another instance. This works in both the development and production environments.

The BACKEND_ID and INSTANCE_ID environment variables contain the backend name and instance index of the instance handling the request.

修改您的 url 以包含您的后端名称(来自您的 backends.yaml),如果其他配置正确,您应该可以访问它。

关于同一主题的更多信息:

Backends share the handlers defined in app.yaml with the main application version. You can place your backends in a separate application root directory if you want to avoid sharing code or handlers, or simply mark the relevant handlers with login: admin.

如果您想获得更深入的答案,如果您发布了 backends.yaml、app.yaml 和处理程序,这可能会有所帮助。

关于Python App Engine 后端为 cron 工作,但如果我直接点击 url 则不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13178828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com