UNPKG

strapi-plugin-publisher

Version:

A plugin for Strapi Headless CMS that provides the ability to schedule publishing for any content type.

29 lines (25 loc) 700 B
import getPluginService from '../utils/getPluginService'; const registerCronTasks = ({ strapi }) => { const settings = getPluginService('settingsService').get(); // create cron check strapi.cron.add({ publisherCronTask: { options: settings.actions.syncFrequency, task: async () => { // fetch all actions that have passed const records = await getPluginService('action').find({ filters: { executeAt: { $lte: new Date(Date.now()), }, }, }); // process action records for (const record of records.results) { getPluginService('publicationService').toggle(record, record.mode); } }, }, }); } export default registerCronTasks;