File tree Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -16610,7 +16610,7 @@ Language: TypeScript
1661016610File path: src/index.ts
1661116611
1661216612```ts
16613- let unsubscribeCreate: (() => void) | undefined;
16613+ let cronJobKey: string | undefined;
1661416614
1661516615export default {
1661616616 register({ strapi }) {
@@ -16622,13 +16622,22 @@ export default {
1662216622 },
1662316623
1662416624 async bootstrap({ strapi }) {
16625- unsubscribeCreate = strapi.eventHub.subscribe('entry.create', (event) => {
16626- strapi.log.info(`New entry created in ${event.model}: ${event.result?.id}`);
16625+ cronJobKey = 'log-reminders';
16626+
16627+ strapi.cron.add({
16628+ [cronJobKey]: {
16629+ rule: '0 */6 * * *', // every 6 hours
16630+ job: async () => {
16631+ strapi.log.info('Remember to review new content in the admin panel.');
16632+ },
16633+ },
1662716634 });
1662816635 },
1662916636
16630- async destroy() {
16631- unsubscribeCreate?.();
16637+ async destroy({ strapi }) {
16638+ if (cronJobKey) {
16639+ strapi.cron.remove(cronJobKey);
16640+ }
1663216641 },
1663316642};
1663416643```
Original file line number Diff line number Diff line change @@ -7166,7 +7166,7 @@ All 3 lifecycle functions can be put together to configure custom behavior durin
716671663. Restart Strapi to confirm each lifecycle executes in sequence.
71677167
71687168```ts title="src/index.ts"
7169- let unsubscribeCreate: (() => void) | undefined;
7169+ let cronJobKey: string | undefined;
71707170
71717171 register({ strapi }) {
71727172 strapi.customFields.register({
@@ -7177,13 +7177,22 @@ let unsubscribeCreate: (() => void) | undefined;
71777177 },
71787178
71797179 async bootstrap({ strapi }) {
7180- unsubscribeCreate = strapi.eventHub.subscribe('entry.create', (event) => {
7181- strapi.log.info(`New entry created in ${event.model}: ${event.result?.id}`);
7180+ cronJobKey = 'log-reminders';
7181+
7182+ strapi.cron.add({
7183+ [cronJobKey]: {
7184+ rule: '0 */6 * * *', // every 6 hours
7185+ job: async () => {
7186+ strapi.log.info('Remember to review new content in the admin panel.');
7187+ },
7188+ },
71827189 });
71837190 },
71847191
7185- async destroy() {
7186- unsubscribeCreate?.();
7192+ async destroy({ strapi }) {
7193+ if (cronJobKey) {
7194+ strapi.cron.remove(cronJobKey);
7195+ }
71877196 },
71887197};
71897198```
You can’t perform that action at this time.
0 commit comments