From 0568e4ca0f09c1f703f0914c610aaf8258aaa447 Mon Sep 17 00:00:00 2001 From: Cameron Paczek Date: Wed, 15 Feb 2023 23:23:17 -0800 Subject: [PATCH 1/2] convert to cron object format --- cron-task.js | 67 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/cron-task.js b/cron-task.js index 2a00a3a..f9313cf 100644 --- a/cron-task.js +++ b/cron-task.js @@ -1,36 +1,39 @@ module.exports = { - "*/30 * * * *": async ({ strapi }) => { - const posts = await strapi.db - .query("plugin::scheduler.scheduler") - .findMany({ where: { scheduledDatetime: { $lte: new Date() } } }); - - posts.map(async (post) => { - if (post.scheduleType === "schedule") { - - await strapi.db.query(post.uid).update({ - where: { - id: post.contentId, - }, - data: { - publishedAt: new Date(), - }, - }); - await strapi.db + webbioSchedulerCron: { + rule: "*/30 * * * *", + task: async ({ strapi }) => { + const posts = await strapi.db .query("plugin::scheduler.scheduler") - .delete({ where: { id: post.id } }); - } else if (post.scheduleType === "depublish") { - await strapi.db.query(post.uid).update({ - where: { - id: post.contentId, - }, - data: { - publishedAt: null, - }, + .findMany({ where: { scheduledDatetime: { $lte: new Date() } } }); + + posts.map(async (post) => { + if (post.scheduleType === "schedule") { + + await strapi.db.query(post.uid).update({ + where: { + id: post.contentId, + }, + data: { + publishedAt: new Date(), + }, + }); + await strapi.db + .query("plugin::scheduler.scheduler") + .delete({ where: { id: post.id } }); + } else if (post.scheduleType === "depublish") { + await strapi.db.query(post.uid).update({ + where: { + id: post.contentId, + }, + data: { + publishedAt: null, + }, + }); + await strapi.db + .query("plugin::scheduler.scheduler") + .delete({ where: { id: post.id } }); + } }); - await strapi.db - .query("plugin::scheduler.scheduler") - .delete({ where: { id: post.id } }); - } - }); -}, + }, + } }; From 36a0ad7c2a152453459ea5b2d186629484d06869 Mon Sep 17 00:00:00 2001 From: Cameron Paczek Date: Wed, 15 Feb 2023 23:29:54 -0800 Subject: [PATCH 2/2] fix typo --- cron-task.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cron-task.js b/cron-task.js index f9313cf..f8f35b2 100644 --- a/cron-task.js +++ b/cron-task.js @@ -1,6 +1,8 @@ module.exports = { webbioSchedulerCron: { - rule: "*/30 * * * *", + options: { + rule: "*/30 * * * *", + }, task: async ({ strapi }) => { const posts = await strapi.db .query("plugin::scheduler.scheduler")