wizbii / strapi-plugin-strapi-algolia

A strapi plugin that index items to algolia
https://market.strapi.io/plugins/strapi-plugin-strapi-algolia
9 stars 3 forks source link

Correct way to call from Cron Job #7

Closed alexolivier closed 3 weeks ago

alexolivier commented 2 months ago

I've been trying to setup a native cronjob to call this for indexing, and landed on the following which doesn't feel right. Do you have a recommended approach?


module.exports = {
  algolia: {
    task: async ({ strapi }) => {
      try {
        const indexer =
          strapi.plugins["strapi-algolia"].controllers[
            "strapi-algolia-index-articles"
          ].index;

        await indexer({
          request: { body: { name: "api::article.article" } },
          send: console.log,
        });
      } catch (e) {
        console.error(e);
      }
    },
    options: {
      rule: "0 * * * *",
    },
  },
};
squelix commented 2 months ago

Mmm, for me it's a good solution, we didn't put the index-all method into a service, so it's the good way to call it.