简体   繁体   English

用于 python2.7 谷歌应用引擎的 Cloud Tasks API

[英]Cloud Tasks API for python2.7 google app engine

I have created a project under Google App Engine Python 2.7.我在 Google App Engine Python 2.7 下创建了一个项目。 I have created some tasks using queue.yaml and deployed with the glcoud command.我使用queue.yaml创建了一些任务并使用glcoud命令进行部署。 When I go to the Google App Engine console under section "taskqueues", it redirects to the Cloud Tasks page.当我转到“taskqueues”部分下的 Google App Engine 控制台时,它会重定向到 Cloud Tasks 页面。 I can see my App Engine queues are listed under Cloud Tasks.我可以看到我的 App Engine 队列列在 Cloud Tasks 下。

I have still not enabled 'Cloud Tasks API' service but when I launch background task which service is handling the queue?我还没有启用“云任务 API”服务,但是当我启动后台任务时,哪个服务正在处理队列? Then if I want to use Cloud Tasks service with App Engine Python 2.7, how should I proceed?那么如果我想在 App Engine Python 2.7 中使用 Cloud Tasks 服务,我应该如何进行?

I have followed documentation https://cloud.google.com/tasks/docs/dual-overview in which for Python 2.7 we can access Cloud Tasks service via App engine Task Queue API.我遵循了文档https://cloud.google.com/tasks/docs/dual-overview ,其中对于 Python 2.7,我们可以通过 App Engine Task Queue API 访问 Cloud Tasks 服务。 There are some key deferences using Cloud Tasks API service such as deferred queues.使用 Cloud Tasks API 服务有一些关键的差异,例如延迟队列。 I just want to make sure that these features will be available when I move to Cloud Tasks.我只是想确保当我转移到 Cloud Tasks 时这些功能将可用。 How can both services coexist?两种服务如何共存?

The "Cloud Tasks API" provides a REST API that you can use to add tasks from a second generation App Engine standard environment runtime, any of the App Engine flexible environment runtimes, or even from entirely outside of App Engine. “Cloud Tasks API”提供了一个 REST API,您可以使用它从第二代 App Engine 标准环境运行时、任何 App Engine 灵活环境运行时,甚至完全在 App Engine 之外添加任务。

When you're creating first-generation App Engine push/pull queues, you're bypassing the need to use this API directly, however the tasks that are being created are on the same service as if you had created them with the Cloud Tasks API.当您创建第一代 App Engine 推/拉队列时,您无需直接使用此 API,但是正在创建的任务在同一服务上,就像您使用 Cloud Tasks API 创建它们一样.

In the 1st generation standard environment GAE (python 2.7) services you should continue to use the Task Queue API, there is no deprecation note for it.在第一代标准环境 GAE (python 2.7) 服务中,您应该继续使用任务队列 API,没有弃用说明。

Task Queue API is not available in the other environments, so for those services you have to use the newer Cloud Tasks API (which at least initially was based on a 1st gen standard environment service under the hood, but now it supports multiple HTTP endpoints). Task Queue API 在其他环境中不可用,因此对于这些服务,您必须使用较新的 Cloud Tasks API(至少最初是基于第一代标准环境服务,但现在它支持多个 HTTP 端点) .

You shouldn't worry too much about the Cloud Tasks page - it just make sense to manage both through a common GUI due to their similarities, but the 2 products continue to operate independently.您不必太担心 Cloud Tasks 页面 - 由于它们的相似性,通过通用 GUI 管理两者才有意义,但是这两种产品继续独立运行。 Depending on which API you use you could, I suppose, use both features in the same time (for different tasks, of course) and manage both through the common GUI.我想,根据您使用的 API,您可以同时使用这两个功能(当然,对于不同的任务)并通过通用 GUI 管理这两个功能。

You can't exactly talk about which service handles a queue as tasks in the same queue could be handled by different services.您不能确切地谈论哪个服务处理队列,因为同一队列中的任务可以由不同的服务处理。 For example in GAE push queues there are 3 ways for targeting a task:例如,在 GAE 推送队列中,有 3 种方法可以定位任务:

  • Declare the target when you construct the task.在构建任务时声明目标。 You can set the target explicitly using the target parameter in the taskqueue.add() function.您可以使用taskqueue.add()函数中的target参数显式设置目标。 See the example above.请参阅上面的示例。
  • Include a target directive when you define a queue in the queue.yaml , as in the definition of queue-blue .queue.yaml定义队列时包括target指令,如queue-blue定义 All tasks added to a queue with a target will use that target, even if a different target was assigned to the task at construction time.添加到具有target的队列的所有任务都将使用该目标,即使在构建时为任务分配了不同的目标。
  • If no target is specified according to either of the previous two methods, then the task's target is the version of the service that enqueues it.如果根据前两种方法中的任何一种都没有指定目标,则任务的目标是将其加入队列的服务的版本。 Note that if you enqueue a task from the default service and version in this manner, and the default version changes before the task executes, it will run in the new default version.请注意,如果您以这种方式将任务从默认服务和版本中排入队列,并且在任务执行之前默认版本发生变化,它将在新的默认版本中运行。

In Cloud Tasks targeting is even wider - a task target isn't even necessarily a GAE service.在 Cloud Tasks 中,目标范围更广——任务目标甚至不一定是 GAE 服务。 From Cloud Tasks queues with HTTP targets :带有 HTTP 目标的 Cloud Tasks 队列

In the case of generic HTTP Targets, the Cloud Tasks service forwards the task request to the worker, located at any generic HTTP endpoint, such as Cloud Functions , Cloud Run , GKE , Compute Engine , or even an on-prem web server, and based on how the task is configured.对于通用 HTTP 目标,Cloud Tasks 服务将任务请求转发给位于任何通用 HTTP 端点(例如Cloud FunctionsCloud RunGKECompute Engine甚至本地 Web 服务器)的工作线程,以及基于任务的配置方式。

The deferred queues is similarly misleading, you should be referring to deferred tasks.延迟队列同样具有误导性,您应该指的是延迟任务。 In general there are 2 main reasons for using them:一般来说,使用它们有两个主要原因:

In some cases where you might need a series of diverse small tasks handled asynchronously but you don't want to go through the work of setting up individual distinct handlers, the App Engine SDK allows you to use runtime specific libraries to create simple functions to manage these tasks.在某些情况下,您可能需要异步处理一系列不同的小任务,但又不想完成设置各个不同处理程序的工作,App Engine SDK 允许您使用运行时特定库来创建简单的函数来管理这些任务。 This feature is not available in Cloud Tasks.此功能在 Cloud Tasks 中不可用。 Note, though, that normal tasks can be scheduled in the future using Cloud Tasks.但请注意,以后可以使用 Cloud Tasks 安排正常任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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