当strapi服务的方法被称为时,Strapi V3中的Cron Job不会触发

发布于 2025-01-26 16:16:42 字数 519 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2025-02-02 16:16:42

找到了解决方案。将其发布在这里,以便将来可以帮助其他人。

两个CRON任务的时间格式都是相同的。当我检查Strapi配置中的活动cron列表时;只有一个Cron任务可用。似乎作为导出的钥匙是相同的,第二个条目覆盖了第一个。当我为差异任务编写diff时间格式时,主动cron作业的列表显示了所有CRON任务。

以下命令将帮助您检查活动的CRON任务列表。

npm run strapi console 
const strapi = require('strapi');
strapi().config

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.

npm run strapi console 
const strapi = require('strapi');
strapi().config
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文