定时任务如何传递参数?啥时候能定义多个trigger?
发布于 7 年前 作者 maqiang 11339 次浏览 来自 官方Issues

需求:

我现在有一个云函数cloudFuncA,里面有2个方法:methodA和methodB,我需要在每天0点的时候,运行methodA,每天早上5点运行methodB。

我现在另外整了2个云函数:

cloudFuncB ,这里面带一个定时配置,每天0点运行,会调用cloudFuncA.methodA完成一些工作。

cloudFuncC,这里面带一个定时配置<span style="font-size: 16px;">,每天5点运行,会调用cloudFuncA.methodB完成一些工作。</span>

sfsg,但是我就是觉得挺闹心的,你看看:

//cloudFunctionB/config.js
{
  "triggers": [
    {
      "name""launch-every-day",
      "type""timer",
      "config""0 0 0 * * * *"
    }
  ]
}

在看看cloudFuncB的主体内容:

exports.main = async (event, context) => {
  const result = await cloud.callFunction(
    {
      'name''cloudFuncA',
      data: {
        '$url''methodA'
      }
    });
  return result;
}

看看这个cloudFuncB,里面几乎啥都没有,你说这叫啥事儿? 不是典型的逼死强迫症的节奏吗?

你们鹅厂那么多牛人,能不能把这事儿给解决了?

// 看看这,不亦乐乎?
{
  "triggers": [
    {
      "name""launch-every-day-每天0点",
      "type""timer",
      "config""0 0 0 * * * *",
      "data": {
        "$url""methodA",
        ...
      }
    },
    {
      "name""launch-every-day-每天5点",
      "type""timer",
      "config""0 0 5 * * * *",
      "data": {
        "$url""methodB",
        ...
      }
    },
  ]
}
回到顶部