简体   繁体   中英

Cron job in strapi V3 does not get triggered when a method from strapi services is called

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM