云任务函数未触发-任何需要App Engine的资源都只能在App Engine区域创建/更新 [英] Cloud Task function not firing -Any resource that needs App Engine can only be created/updated in the App Engine region
问题描述
我的处理程序名为taskToFireOff已删除allUsers
,Cloud Tasks Enqueuer
主体的名称设置为ServiceAccountEmail
,其角色设置为Invoker
(未显示)
创建帖子时,我使用.onCreate
创建任务。任务已创建,但http请求所连接的函数从不触发。我看了看这里https://console.cloud.google.com/cloudtasks/queue/,发现有两个任务(我尝试了两次)就坐在那里。
当我转到控制台中的云任务页面时&>单击任务>;任务&>Method / URL
,它显示
POSThttps://us-east1-myProjectId.cloudfunctions.net/taskToFireOff
但当我转到任务&>日志&>查看&>建议&>查询详细信息时,它会显示
在onCreateData中看到新错误组:错误:3无效参数:ANY 需要App Engine的资源只能在App中创建/更新 引擎区。位置必须等于us-East1,因为应用程序
这是一个奇怪的错误,因为上面的url以us-east1开头,而在我的index.js文件中,我使用us-east1
设置了位置exports.onCreateData = functions.database.ref('/posts/{postId}').onCreate(async (snapshot, context) => {
const payload = {"postId": context.params.postId};
const project = JSON.parse(process.env.FIREBASE_CONFIG!).projectId;
const location = 'us-east1';
const queue = 'ttl-task';
const serviceAccountEmail = 'yaddayadda@myProjectId.iam.gserviceaccount.com';
const queuePath = tasksClient.queuePath(project, location, queue);
const url = `https://${location}-${project}.cloudfunctions.net/taskToFireOff`
const task = {
httpRequest: {
httpMethod: 'POST',
url,
oidcToken: {
serviceAccountEmail
},
body: Buffer.from(JSON.stringify(payload)).toString('base64'), // JSON.parse(JSON.stringify(payloadData));
headers: {
'Content-Type': 'application/json',
},
},
scheduleTime: {
seconds: // ...
}
}
const [response] = await tasksClient.createTask({ parent: queuePath, task });
// ...
});
exports.taskToFireOff = functions.https.onRequest((request, response) => {
// ...
});
在控制台中,当我单击任务本身并查看有效负载时,所有正确的信息都在那里。
当我创建我的实时数据库时,我收到了us-central1
us-east1
。在FiRestore数据库的底部显示
当我输入$ gcloud app describe
时,它显示LocationID为us-east1
会不会是云任务在us-east1
而云函数在us-central1
?
运行$ gcloud functions list
会列出us-central1
区域中的所有云函数
Multi-region nam5(us-central
),但us-central1
没有特定的区域。我选择了us-east1
,因为我在纽约。推荐答案
问题是应用程序引擎在us-east1
中,但函数处理程序taskToFireOff在us-central1
中。错误是说App Engine/Cloud任务关联的函数需要一起位于同一地域。简而言之,我需要更改该特定云函数的区域。
要解决这个问题,我必须创建一个新的处理程序,这非常简单。我按照answer的说明进入了link,特别是更改函数的一个或多个区域部分。
我运行的第一个终端:
$ gcloud app describe
// use whatever appears for the locationId which for me was us-east1
Second-我将此新函数添加到index.js文件:
// whatever appeared for the locationId I put inside the region param
exports.newTaskToFireOff = functions.region('us-east1').https.onRequest((request, response) => {
// ... in here I c+p all of the code from my initial taskToFireOff function
});
3-我在终端中运行此命令,以使用新函数更新gCloud
$ firebase deploy --only functions:newTaskToFireOff
4-我在终端中运行此命令,以便从gCloud中删除旧函数:
$ firebase functions: delete taskToFireOff
5-我进入index.js文件,手动删除了整个taskToFireOff。您不需要旧函数,只需要它内部的代码
// I deleted this old function
exports.taskToFireOff = functions.https.onRequest((request, response) => {
// ... I took this code and c+p inside the newTaskToFireOff before I deleted this function
});
7-
当我转到控制台的Cloud Functions page旧taskToFireOff不再存在,而新TaskToFireOff存在区域us-east1
Permissions
。将角色设置为Invoker
,并将其主要角色名称设置为使用您为云任务ServiceAccountEmail
设置的任何内容,否则它仍然无法工作。您也应该删除allUsers
。
这篇关于云任务函数未触发-任何需要App Engine的资源都只能在App Engine区域创建/更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!