使用自定义名称在Google Cloud上创建cron作业



阅读Nodejs调度器的文档,我没有找到如何为我想要创建的cron作业传递名称。

有人知道这个包是否支持这个吗?

我试着:

> const job = {
>         httpTarget: {
>           uri: `my_url`,
>           httpMethod: 'GET',
>         },
>         schedule: '0 0,8-17 * * 0-6',
>         timeZone: 'my_timezone',
>         body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
>         name: 'custom_name'
>       };

查看Cloud Scheduler作业资源的API规范和Nodejs快速入门,我认为您需要在httpTarget中移动body属性,因为作业资源没有body属性,它应该与http请求相关联。

根据你的代码,你最终会想要这样的东西:

const job = {
httpTarget: {
uri: 'my_url',
httpMethod: 'GET',
body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
},
schedule: '0 0,8-17 * * 0-6',
timeZone: 'my_timezone',
name: 'custom_name'
};

我弄清楚了什么是错误的,为了正确设置名称,我们需要设置名称与project_id和location_id

httpTarget: {
uri: 'my_url',
httpMethod: 'GET',

},
schedule: '0 0,8-17 * * 0-6',
timeZone: 'my_timezone',
name: 'projects/YOUR_PROJECT_ID/locations/YOUR_LOCATION_ID/jobs/YOUR_CUSTOM_JOB_NAME'
};

最新更新