diff --git a/core/server/adapters/scheduling/SchedulingBase.js b/core/server/adapters/scheduling/SchedulingBase.js index 8b9fa98056..15d401a7d8 100644 --- a/core/server/adapters/scheduling/SchedulingBase.js +++ b/core/server/adapters/scheduling/SchedulingBase.js @@ -1,6 +1,6 @@ function SchedulingBase() { Object.defineProperty(this, 'requiredFns', { - value: ['schedule', 'unschedule', 'reschedule', 'run'], + value: ['schedule', 'unschedule', 'run'], writable: false }); } diff --git a/core/server/adapters/scheduling/SchedulingDefault.js b/core/server/adapters/scheduling/SchedulingDefault.js index c2727a2f2f..50ce11c1f5 100644 --- a/core/server/adapters/scheduling/SchedulingDefault.js +++ b/core/server/adapters/scheduling/SchedulingDefault.js @@ -59,11 +59,9 @@ SchedulingDefault.prototype.schedule = function (object) { }; /** - * @description Remove & schedule a job. + * @description Unschedule a job. * - * This function is useful if the model layer detects a rescheduling event. - * Rescheduling means: scheduled -> update published at. - * To be able to delete the previous job we need the old published time. + * Unscheduling means: scheduled -> draft. * * @param {Object} object * { @@ -79,39 +77,18 @@ SchedulingDefault.prototype.schedule = function (object) { * bootstrap: [Boolean] * } */ -SchedulingDefault.prototype.reschedule = function (object, options = {bootstrap: false}) { +SchedulingDefault.prototype.unschedule = function (object, options = {bootstrap: false}) { /** * CASE: - * The post scheduling unit calls "reschedule" on bootstrap, because other custom scheduling implementations + * The post scheduling unit triggers "reschedule" on bootstrap, because other custom scheduling implementations * could use a database and we need to give the chance to update the job (delete + re-add). * * We receive a "bootstrap" variable to ensure that jobs are scheduled correctly for this scheduler implementation, * because "object.extra.oldTime" === "object.time". If we mark the job as deleted, it won't get scheduled. */ if (!options.bootstrap) { - this._deleteJob({time: object.extra.oldTime, url: object.url}); + this._deleteJob(object); } - - this._addJob(object); -}; - -/** - * @description Unschedule a job. - * - * Unscheduling means: scheduled -> draft. - * - * @param {Object} object - * { - * time: [Number] A unix timestamp - * url: [String] The full post/page API url to publish it. - * extra: { - * httpMethod: [String] The method of the target API endpoint. - * oldTime: [Number] The previous published time. - * } - * } - */ -SchedulingDefault.prototype.unschedule = function (object) { - this._deleteJob(object); }; /** diff --git a/core/server/adapters/scheduling/post-scheduling/index.js b/core/server/adapters/scheduling/post-scheduling/index.js index 1fa6b1d5fa..a8810f6783 100644 --- a/core/server/adapters/scheduling/post-scheduling/index.js +++ b/core/server/adapters/scheduling/post-scheduling/index.js @@ -148,7 +148,7 @@ exports.init = function init(options = {}) { // and not an in-process implementation! Object.keys(scheduledResources).forEach((resourceType) => { scheduledResources[resourceType].forEach((model) => { - adapter.unschedule(_private.normalize({model, apiUrl, integration, resourceType}, 'unscheduled')); + adapter.unschedule(_private.normalize({model, apiUrl, integration, resourceType}, 'unscheduled'), {bootstrap: true}); adapter.schedule(_private.normalize({model, apiUrl, integration, resourceType})); }); }); diff --git a/core/test/unit/adapters/scheduling/SchedulingDefault_spec.js b/core/test/unit/adapters/scheduling/SchedulingDefault_spec.js index 5afc9078a3..32729a28ca 100644 --- a/core/test/unit/adapters/scheduling/SchedulingDefault_spec.js +++ b/core/test/unit/adapters/scheduling/SchedulingDefault_spec.js @@ -74,7 +74,8 @@ describe('Scheduling Default Adapter', function () { } }); - scope.adapter.reschedule({ + /**Reschedule is now unschedule+schedule */ + scope.adapter.unschedule({ time: time, url: 'something', extra: { @@ -82,6 +83,14 @@ describe('Scheduling Default Adapter', function () { method: 'PUT' } }); + scope.adapter.schedule({ + time: time, + url: 'something', + extra: { + oldTime: null, + method: 'PUT' + } + }); setTimeout(() => { scope.adapter._pingUrl.calledOnce.should.eql(true); @@ -94,7 +103,7 @@ describe('Scheduling Default Adapter', function () { const time = moment().add(20, 'milliseconds').valueOf(); - scope.adapter.reschedule({ + scope.adapter.unschedule({ time: time, url: 'something', extra: { @@ -103,6 +112,15 @@ describe('Scheduling Default Adapter', function () { } }, {bootstrap: true}); + scope.adapter.schedule({ + time: time, + url: 'something', + extra: { + oldTime: null, + method: 'PUT' + } + }); + setTimeout(() => { scope.adapter._pingUrl.calledOnce.should.eql(true); done();