strapi-community / strapi-plugin-publisher

A plugin for Strapi Headless CMS that provides the ability provides the ability to easily schedule publishing and unpublishing of any content type.
https://market.strapi.io/plugins/strapi-plugin-publisher
MIT License
48 stars 17 forks source link

[bug] Cron tasks is executing every minute publisher plugin is disabled #37

Closed jsanta closed 1 year ago

jsanta commented 1 year ago

In config/plugins.js file publisher is set to disable:

    publisher: {
    enabled:  false,
    }

Looking at the log the cron task is executing every minute, regardless of the publisher plugin being disabled. Web console is OK as the publisher buttons are not being showed, but the log shows that the crontask '/1 *' still executes itself. Cron task should at least verify the plugin is activated in order to avoid not useful executions.

Found out because I'm getting this error:

9|strapi-prod  | 2022-12-20T18:13:00: KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
9|strapi-prod  | 2022-12-20T18:13:00:     at Client_PG.acquireConnection (/opt/apps/strapi-prod/node_modules/knex/lib/client.js:310:26)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Runner.ensureConnection (/opt/apps/strapi-prod/node_modules/knex/lib/execution/runner.js:294:28)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Runner.run (/opt/apps/strapi-prod/node_modules/knex/lib/execution/runner.js:30:19)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Object.execute (/opt/apps/strapi-prod/node_modules/@strapi/database/lib/query/query-builder.js:396:22)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Object.findMany (/opt/apps/strapi-prod/node_modules/@strapi/database/lib/entity-manager/index.js:142:22)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Object.findMany (/opt/apps/strapi-prod/node_modules/@strapi/strapi/lib/services/entity-service/index.js:313:20)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Object.findMany (/opt/apps/strapi-prod/node_modules/@strapi-community/strapi-plugin-url-alias/server/admin-api/services/override-query-layer.js:17:28)
9|strapi-prod  | 2022-12-20T18:13:00:     at async Object.*/1 * * * * (/opt/apps/strapi-prod/node_modules/strapi-plugin-publisher/server/config/cron-tasks.js:11:21)

Tried hot patching the cron string to 0 0 /30 * but it still shows the error with the 1 minute cron string. Also related (but I've seen that this is a common mis-practice in most Strapi development) all propmises are treated in an optimistic way. All Promise based functions use async-await without considering that something can (and will) probably fail, so there's no error catching.

Strapi version: 4.4.3 Publisher plugin version: 1.1.3 (checked vs Github and cront-task.js file is the same I have on my installation).

ComfortablyCoding commented 1 year ago

That's strange. The bootstrap function (and therefore the Cron setup) should not run if the plugin is disabled.

For the Cron frequency, I can add setting an option for the ability to specify the expression to be used for the check.

In terms of the scarcity of try/catch I agree, error handling is a good idea :)

jsanta commented 1 year ago

Both the cron frequency and try-catchs would be nice improvements! :)

ComfortablyCoding commented 1 year ago

This has been fixed in the latest release (v1.2.0)