我想做的是在计划的时间使用云功能和云任务更改Firestore中的数据。但是云任务不能按时运行。添加任务后立即执行。
我的代码是这样的。
index.js
exports.addTasks = functions.https.onCall((data, context) => {
const client = new tasks.CloudTasksClient()
const projectId = ...
const queue = ...
const location = ...
const parent = client.queuePath(projectId, location, queue)
const url = ... .cloudfunctions.net/doSomething?docId=' + docId
const task = {
httpRequest: {
httpMethod: 'POST',
url: url,
scheduleTime: {
seconds: 3 * 60 + Date.now() / 1000,
},
}
}
const request = {
parent: parent,
task: task,
}
client.createTask(request)
})
exports.doSomething = functions.https.onRequest((req, res) => {
var db = admin.firestore()
var docId = req.query.docId
var docRef = db.collection('people').doc(docId)
docRef.update({
changeHere: true,
})
})
我想在执行doSomething
后三分钟运行addTasks
函数。我这是怎么了?
答案 0 :(得分:1)
scheduleTime
是任务对象的属性,而不是httpRequest
的属性。
const task = {
httpRequest: {
httpMethod: 'POST',
url: url,
},
scheduleTime: {
seconds: 3 * 60 + Date.now() / 1000,
},
}
这是reference doc和sample code上显示的内容。