如何在任何集合的 onWrite 之后部署 cron 作业云函数

How to deploy a cron job cloud function after onWrite of any collection

根据documentation下面是运行ning一个cron作业的代码

exports.cronJob = functions.pubsub.schedule('5 11 * * *')
  .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
  .onRun((context) => {
  console.log('This will be run every day at 11:05 AM Eastern!');
  return null;
});

但我想 运行 在

中检测到任何更改时执行 cron 作业
exports.changeDetected = functions.firestore
  .document('/myTable/{myID}')
  .onWrite((snapshot, context) => {
    const dataAfterWrite = snapshot.after.data();
    const myID = context.params.myID;
    /*I want to deploy a cron job cloud function from here with the name of myID. something like this:

  exports.{$`myID`} = functions.pubsub.schedule('5 11 * * *')
  .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
  .onRun((context) => {
  console.log('This will be run every day at 11:05 AM Eastern!');
  return null;
});
 */      
    return true;
  });

是否可以在 firebase 云函数中执行此操作?当检测到任何集合中的任何更改时,我们可以部署 firebase cron 作业云函数吗?

让一个函数动态部署另一个函数不太可行。我建议改为创建一个定期运行的单个函数,并让它检查以查看在它触发时应该完成哪些工作。可以使用 Firestore 中的文档来描述这项工作,因此您所要做的就是查询这些文档,并根据您找到的内容采取行动。