2

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

这是 cron 的样子:
url: /cron/my_job_name
target: mybackend
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

应用程序.yaml
url: /cron/my_job_name
script: path/my_job_name.py
login: admin

后端.yaml
name: mybackend
class: B8
instances: 1
options: dynamic

4

1 回答 1

1

It sounds like when you are hitting your URL, you are not actually invoking a backend instance to handle it.

From the 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.

Modify your url to include your backend name (from you backends.yaml) and you should be able to access it, provided other configs are correct.

More on that same topic:

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.

It might be helpful if you posted your backends.yaml, app.yaml and handlers if you would like a more in depth answer.

于 2012-11-01T14:19:24.743 回答