云任务未按时运行

Oot*_*oto 0 google-cloud-platform google-cloud-functions google-cloud-tasks

我想做的是在计划的时间使用云功能和云任务更改 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,
  })
})
Run Code Online (Sandbox Code Playgroud)

我想在执行doSomething后 3 分钟运行函数。addTasks我这有什么错吗?

Ave*_*sch 6

scheduleTime是任务对象的属性,而不是 的属性httpRequest

  const task = {
    httpRequest: {
      httpMethod: 'POST',
      url: url,
    },
    scheduleTime: {
      seconds: 3 * 60 + Date.now() / 1000,
    }, 
  }
Run Code Online (Sandbox Code Playgroud)

这是显示这一点的参考文档示例代码。