Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log on Failed Publishs from Scheduler #590

Merged
merged 5 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/services/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ function publishExternally(url) {
return bluebird.try(function () {
const published = replaceVersion(url, 'published');

return rest.putObject(published);
return rest.putObject(published)
.then(function (res) {
if (res && !res.ok) {
log('error', 'failed to publish url from schedule', {
url
});
}
return res;
});
});
}

Expand Down Expand Up @@ -205,6 +213,7 @@ module.exports.stopListening = stopListening;
module.exports.setScheduleInterval = setScheduleInterval;

// For testing
module.exports.publishExternally = publishExternally;
module.exports.setLog = function (fakeLogger) {
log = fakeLogger;
};
35 changes: 35 additions & 0 deletions lib/services/schedule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ describe(_.startCase(filename), function () {
sandbox.clock.tick(intervalDelay);
});

it('logs if the publish request is not ok', function (done) {
const uri = 'http://abce',
scheduledItem = {at: intervalDelay - 1, publish: uri},
data = {key:'some-key', value: JSON.stringify(scheduledItem)};

rest.putObject.returns(bluebird.resolve({ok: false}));
siteService.sites.returns([{host: 'a', path: '/'}]);
db.pipeToPromise.returns(bluebird.resolve(JSON.stringify([data])));
db.get.returns(bluebird.resolve(JSON.stringify(scheduledItem)));
db.batch.returns(bluebird.resolve());

lib.setLog(function (logType, msg) {
expect(logType).to.equal('error');
expect(msg).to.match(/failed to publish/);
done();
});

fn();
sandbox.clock.tick(intervalDelay);
});

it('logs error if failed to parse JSON', function (done) {
const uri = 'abce/_pages/abcd',
data = {key:'some-key', value: JSON.stringify({at: intervalDelay - 1, publish: uri}).substring(5)};
Expand Down Expand Up @@ -185,4 +206,18 @@ describe(_.startCase(filename), function () {
sandbox.clock.tick(intervalDelay);
});
});

describe('publishExternally', function () {
const fn = lib[this.title];

it('handles a false-y response from the rest service', function () {
const uri = 'http://abce';

rest.putObject.returns(bluebird.resolve(null));
return fn(uri)
.then(function (res) {
expect(res).to.be.null;
});
});
});
});