🏗 Removed `reschedule` method from scheduling adapter

no issue

We changed `reschedule` event to trigger adapter's `unschedule` and  `schedule` methods since we now generate separate tokens(urls) for consistency as two different url(token) is needed to complete the reschedule functionality.
This commit is contained in:
Rish 2019-11-20 12:16:26 +05:30 committed by Rishabh Garg
parent d42d112eba
commit b122b683f4
4 changed files with 27 additions and 32 deletions

View File

@ -1,6 +1,6 @@
function SchedulingBase() {
Object.defineProperty(this, 'requiredFns', {
value: ['schedule', 'unschedule', 'reschedule', 'run'],
value: ['schedule', 'unschedule', 'run'],
writable: false
});
}

View File

@ -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);
};
/**

View File

@ -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}));
});
});

View File

@ -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();