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

410 views Asked by At
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!

1

There are 1 answers

0
Chetan Ganji On

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