当strapi服务的方法被称为时,Strapi V3中的Cron Job不会触发
config/functions/cron.js
async function logger() {
console.log("Hello, Im Async");
}
module.exports = {
'*/10 * * * * *': async () => {
console.log("Before);
await strapi.services.collectionName.someMethodName();
console.log("After);
},
'*/10 * * * * *': async () => {
await logger();
},
};
在上面的示例中,记录器被正确调用。但是SomeMethodname根本没有被打电话。也没有印刷之前和之后。我不知道怎么了,如何检查。
相同的代码在分期网站中起作用,但在生产服务器上不起作用。 我不明白正在发生的事情以及如何解决这个问题。
有人知道解决方案吗?
谢谢!
config/functions/cron.js
async function logger() {
console.log("Hello, Im Async");
}
module.exports = {
'*/10 * * * * *': async () => {
console.log("Before);
await strapi.services.collectionName.someMethodName();
console.log("After);
},
'*/10 * * * * *': async () => {
await logger();
},
};
In the example above logger gets called properly. But someMethodName doesn't get called at all. Before and After are also not printed. I dont know what is wrong and how to check it.
Same code works in staging site but not on production server.
I dont understand what is happening and how to solve this.
Does anyone know a solution to this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案。将其发布在这里,以便将来可以帮助其他人。
两个CRON任务的时间格式都是相同的。当我检查Strapi配置中的活动cron列表时;只有一个Cron任务可用。似乎作为导出的钥匙是相同的,第二个条目覆盖了第一个。当我为差异任务编写diff时间格式时,主动cron作业的列表显示了所有CRON任务。
以下命令将帮助您检查活动的CRON任务列表。
Found the solution. Posting it here so that it will help someone else in the future.
Time format for both of the cron tasks is the same. When I checked the list of active cron in the strapi config; there was only one cron task available. It seems that as the key for the export was same, second entry was overriding the first one. When I wrote diff time formats for diff task, list of active cron jobs showed all the cron tasks.
Below commands will help you check the list of active cron tasks.