'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!



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chetan Ganji