After an endpoint was reached, I want to execute a service after a defined expiration time.
That means that I need to use the Strapi instance.
Is there a way to create like a CRON job maybe, but that runs one time, and with a timing set dynamically from the time the code is reached, with an access to the strapi instance ?
I am using Strapi v4
I tried to use setTimeout()
in my services, but it says that strapi is undefined
.
// src/api/my-api/services/my-api.js
module.exports = createCoreService(
'api::my-api.my-api',
({ strapi }) => ({
...
// This service is called by a controller
async myService() {
setTimeout(
async ({ strapi }) => {
await strapi
.service('api::my-api.my-api')
.otherService();
},
10000, // 10 secs for this exemple
{ strapi }
);
}
...
}));