diff --git a/services/project-history/app/js/FlushManager.js b/services/project-history/app/js/FlushManager.js index 526aa57876..cc14277791 100644 --- a/services/project-history/app/js/FlushManager.js +++ b/services/project-history/app/js/FlushManager.js @@ -28,37 +28,18 @@ export function flushIfOld(project_id, cutoffTime, callback) { if (err != null) { return callback(OError.tag(err)) } - // in the normal case, the flush marker will be set with the - // timestamp of the oldest operation in the queue by docupdater - if (firstOpTimestamp != null) { - if (firstOpTimestamp < cutoffTime) { - logger.debug( - { project_id, firstOpTimestamp, cutoffTime }, - 'flushing old project' - ) - return UpdatesProcessor.processUpdatesForProject( - project_id, - ( - err // always clear the flush marker after processing the project - ) => - RedisManager.clearFirstOpTimestamp(project_id, function (e) { - if (e != null) { - logger.error( - { project_id, flushErr: e }, - 'failed to clear flush marker' - ) - } - if (err) { - OError.tag(err) - } - return callback(err) - }) - ) // return the original error from processUpdatesFromProject - } else { - return callback() - } + // In the normal case, the flush marker will be set with the + // timestamp of the oldest operation in the queue by docupdater. + // If the marker is not set for any reason, we flush it anyway + // for safety. + if (!firstOpTimestamp || firstOpTimestamp < cutoffTime) { + logger.debug( + { project_id, firstOpTimestamp, cutoffTime }, + 'flushing old project' + ) + return UpdatesProcessor.processUpdatesForProject(project_id, callback) } else { - return RedisManager.setFirstOpTimestamp(project_id, callback) + return callback() } } ) diff --git a/services/project-history/test/acceptance/js/FlushManagerTests.js b/services/project-history/test/acceptance/js/FlushManagerTests.js index 15e60b2ae1..c25012bc9d 100644 --- a/services/project-history/test/acceptance/js/FlushManagerTests.js +++ b/services/project-history/test/acceptance/js/FlushManagerTests.js @@ -209,7 +209,7 @@ describe('Flushing old queues', function () { ) }) - it('sets the timestamp and does not flush the project history queue', function (done) { + it('flushes the project history queue anyway', function (done) { request.post( { url: `http://localhost:3054/flush/old?maxAge=${3 * 3600}`, @@ -220,8 +220,8 @@ describe('Flushing old queues', function () { } expect(res.statusCode).to.equal(200) assert( - !this.flushCall.isDone(), - 'did not make calls to history service to store updates' + this.flushCall.isDone(), + 'made calls to history service to store updates' ) ProjectHistoryClient.getFirstOpTimestamp( this.projectId, @@ -229,10 +229,7 @@ describe('Flushing old queues', function () { if (err) { return done(err) } - expect(parseInt(result, 10)).to.be.within( - this.startDate, - Date.now() - ) + expect(result).to.be.null done() } )