我想创建一个任务处理程序,该处理程序应该通过重试等处理一些任务。
但我希望这个端点只能由 google 任务中的特定队列触发?
我该怎么处理呢?最佳做法是什么?
此致
google-app-engine google-tasks google-cloud-platform google-cloud-tasks
我的谷歌云任务 API 有问题。我需要创建具有远计划时间的任务。最长计划时间为 30 天。是否有可能增加该限制或绕过某些问题?
我正在使用云任务。仅当任务 A 和任务 B 成功完成时,我才需要触发任务 C 的执行。所以我需要某种方式来读取/通知触发的任务的状态。但我在 GCP 的文档中看不到这样做的方法。使用 Node.js SDK 创建任务并使用 Cloud Functions 作为任务处理程序(如果有帮助的话)。
编辑:
根据要求,以下是有关我们正在做的事情的更多信息:
任务 1 - 10 每个发出 HTTP 请求、获取数据、根据此数据更新 Firestore 中的各个集合。这 10 个任务可以并行运行,并且没有特定的顺序,因为它们彼此之间没有任何依赖性。所有这些任务实际上都是在 GCF 内部实现的。
任务 11 实际上依赖于任务 1 - 10 更新的 Firestore 收集数据。因此它只能在任务 1 - 10 成功完成后才能运行。
我们确实发布 RunID 作为通用标识符来对所有任务 (1 - 11) 的特定运行进行分组。
google-cloud-platform google-cloud-functions google-cloud-tasks
我正在使用 firebase 模拟器在我的计算机上托管一些 GCF 功能。它们被配置为在 localhost:5001 上运行/托管。这很好用。
我现在在我的应用程序中使用 Google Tasks,并且我的任务需要调用 GCF 函数。任务不在本地运行,因此我将我的计算机设置为通过公共 IP 地址访问,并打开端口 5001 以允许该端口上的流量进入。这个想法是Google任务可以调用我机器上的函数,这样我就可以正确测试。
我似乎无法让模拟器与任何外部公共 IP 地址一起工作。这是不可能的吗?如果可以,我该如何配置?
已更新,这里没有太多代码可供查看...我只是想知道您是否可以将模拟器配置为侦听公共端口。这是默认的 firebase.json 文件
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的研究中,我发现你可以添加“host”属性来允许你的本地网络使用“host”:“0.0.0.0”访问模拟器,所以它看起来像这样:这可以允许通过我的本地IP进行访问,例如http://192.168.1.216:5001
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001,
"host": "0.0.0.0"
}, …Run Code Online (Sandbox Code Playgroud) 我正在关注这个教程: https://cloud.google.com/tasks/docs/tutorial-gcf
创建一个将调用云函数的任务。
我已经做了很多尝试,但仍然收到此错误:
如果我将正文编码更改为其他内容,则会收到有关序列化方法的另一个错误。
这可能不是许可问题,因为我之前得到了一些并摆脱了它。
传递给 createTask() 的对象如下:
task: {
httpRequest: {
url: "https://europe-west1-project_id.cloudfunctions.net/FunctionName"
httpMethod: "POST"
oidcToken: {
serviceAccountEmail: "cf-targetFunctionSA@project_id.gserviceaccount.com"
}
body: ""
headers: {
Content-Type: "application/json"
}
}
Run Code Online (Sandbox Code Playgroud)
(或使用 body:base64 编码的 json 字符串。)
我使用的代码如下:
'use strict';
const common = require('./common');
const {v2beta3} = require('@google-cloud/tasks');
const cloudTasksClient = new v2beta3.CloudTasksClient();
let projectName = common.getProjectName();
let location = "europe-west3";
let queue = "compute-stats-on-mysql";
const parent = cloudTasksClient.queuePath(projectName, location, queue);
async function createTask(url, serviceAccount, data)
{
const dataBuffer = Buffer.from(JSON.stringify(data)).toString('base64');
const …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 GCP 文档中提供的 Google Cloud Tasks 代码示例: https: //cloud.google.com/tasks/docs/creating-http-target-tasks(请参阅下面的代码)。但是,从文档中尚不清楚我需要哪个包才能使其工作。有任何想法吗?
但是,我收到以下错误。
ImportError: cannot import name 'tasks_v2' from 'google.cloud'
Run Code Online (Sandbox Code Playgroud)
代码示例:
from google.cloud import tasks_v2
from google.protobuf import timestamp_pb2
# Create a client.
client = tasks_v2.CloudTasksClient()
# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# queue = 'my-appengine-queue'
# location = 'us-central1'
# payload = 'hello'
# Construct the fully qualified queue name.
parent = client.queue_path(project, location, queue)
# Construct the request body.
task = { …Run Code Online (Sandbox Code Playgroud) 我在用
我的要求
由于我的独特要求,我希望1个请求只能由1个实例处理。当它免费或请求超时时,只有这样它才应该收到一个新请求。在实例处理1个请求时,我设法拒绝了其他请求,但无法找出适当的自动缩放设置。
请提出实现此目标的最佳方法。提前致谢!
amazon-web-services node.js express google-cloud-platform google-cloud-tasks
调用尝试创建任务的 firebase HTTP 函数时,我在 firebase 控制台函数日志中收到错误。
错误:7 PERMISSION_DENIED:主体(用户或服务帐户)缺少资源“projects/my-gcloud-project-id/locations/us-central1/queues/myqueuename”(或资源可能不存在)。
也许我对 gcloud id 和位置与 firebase id 和位置之间感到困惑?
编辑:我已通过运行确认我的位置是 us-central1gcloud --project my-gcloud-project-id tasks locations list
或者也许我需要设置权限?
我的代码:
const functions = require('firebase-functions');
const { CloudTasksClient } = require('@google-cloud/tasks')
const projectId = 'my-firebase-project-id';
const location = 'us-central1'
const queue = 'myqueuename'
exports.onFormSubmit = functions.https.onRequest(async (req, res) => {
const tasksClient = new CloudTasksClient()
const queuePath = tasksClient.queuePath('my-gcloud-project-id', location, queue);
const url = `https://google.com/` // edited for stack overflow
const delaySeconds = 5;
console.log('delaying for …Run Code Online (Sandbox Code Playgroud) 我无法让我的 Cloud Tasks 队列停止覆盖应用引擎服务路由。我通过 GCP 仪表板创建了队列,而不是使用 queue.yml 或其他任何东西。
队列说明:
$ gcloud tasks queues describe import
appEngineRoutingOverride:
host: my-project-id.uc.r.appspot.com
name: projects/my-project-id/locations/us-central1/queues/import
purgeTime: '2021-03-31T00:45:22.941195Z'
rateLimits:
maxBurstSize: 100
maxConcurrentDispatches: 1000
maxDispatchesPerSecond: 500.0
retryConfig:
maxAttempts: 100
maxBackoff: 3600s
maxDoublings: 16
minBackoff: 0.100s
state: PAUSED
Run Code Online (Sandbox Code Playgroud)
尝试清除路由覆盖标志--clear-routing-override似乎成功但实际上并未清除该标志
$ gcloud tasks queues update import --clear-routing-override
WARNING: You are managing queues with gcloud, do not use queue.yaml or queue.xml in the future. More details at: https://cloud.google.com/tasks/docs/queue-yaml.
Updated queue [import].
$ gcloud tasks queues describe import
appEngineRoutingOverride: …Run Code Online (Sandbox Code Playgroud) 我在本地主机上使用 Celery + Redis 和 Django Rest API 来运行分类任务,如何从 Axios 帖子获取数据。现在我正在尝试将其部署到谷歌云,并且我没有找到在App Engine上运行Redis和Celery的明确方法,所以我听说了Google任务队列,但我没有找到将其添加到视图和触发器的方法当视图被调用时,我如何创建一个函数来调用我在 celery 上的这个谷歌云任务,或者只是知道如何做到这一点,这些是我的代码:
from celery import shared_task
from celery_progress.backend import ProgressRecorder
from snakeimage.models import Prediction,UploadedSnake,SnakeClass
from snakeimage.classification_codes.classification_codes.prediction_func import predict_classes
#import json
#import time
#from django.conf import settings
#from google.cloud import tasks_v2beta3
#from google.protobuf import timestamp_pb2
@shared_task(bind=True)
def image_progress(self,image_path, X, Y, metadata,image_id):
progress_recorder = ProgressRecorder(self,)
predictions = predict_classes(image_path, X, Y, metadata)
print(predictions)
for prediction in predictions:
print(prediction[0])
image = UploadedSnake.objects.get(id=image_id)
class_name = SnakeClass.objects.get(index=(prediction[0]+1))
print('>>>>>>>>>>>>>>>>>>>>>',prediction[1])
Prediction.objects.create(image=image,class_name=class_name,predict_percent=prediction[1])
progress_recorder.set_progress( 1, 3, description='Prediction Result …Run Code Online (Sandbox Code Playgroud) google-app-engine django-views celery django-celery google-cloud-tasks
node.js ×2
celery ×1
django-views ×1
express ×1
firebase ×1
gcloud ×1
google-tasks ×1
grpc ×1
python ×1