Skip to content

Commit

Permalink
Rename taskSchedule.entitySubmissionBacklog config and default to 5 days
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Aug 30, 2024
1 parent 5b6eb2d commit 4dd1fca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/model/query/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,12 @@ const _deleteHeldSubmissionByEventId = (eventId) => ({ run }) => run(sql`
////////////////////////////////////////////////////////////////////////////////
// FORCE PROCESSING SUBMISSIONS FROM BACKLOG

const DAY_RANGE = config.has('default.taskSchedule.forceProcess')
? config.get('default.taskSchedule.forceProcess')
: 7; // Default is 7 days
// Submissions that have been held in the backlog for longer than 5 days
// will be force-processed, including out-of-order updates and updates
// applied as entity creates.
const DAY_RANGE = config.has('default.taskSchedule.entitySubmissionBacklog')
? config.get('default.taskSchedule.entitySubmissionBacklog')
: 5; // Default is 5 days

const _getHeldSubmissionsAsEvents = (force) => ({ all }) => all(sql`
SELECT audits.* FROM entity_submission_backlog
Expand Down
16 changes: 14 additions & 2 deletions test/integration/api/offline-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,23 @@ describe('Offline Entities', () => {

await exhaust(container);

// One submission should be in the backlog
let backlogCount = await container.oneFirst(sql`select count(*) from entity_submission_backlog`);
backlogCount.should.equal(1);

// Update the timestamp on this to in the past, but less than the default hold duration
await container.run(sql`UPDATE entity_submission_backlog SET "loggedAt" = "loggedAt" - interval '4 days'`);

// The submission should not have been processed
let count = await container.Entities.processBacklog();
count.should.equal(0);

// The submission should still be held in the backlog
backlogCount = await container.oneFirst(sql`select count(*) from entity_submission_backlog`);
backlogCount.should.equal(1);

// Update the timestamp on this backlog
await container.run(sql`UPDATE entity_submission_backlog SET "loggedAt" = "loggedAt" - interval '8 days'`);
await container.run(sql`UPDATE entity_submission_backlog SET "loggedAt" = "loggedAt" - interval '6 days'`);

// Send the next submission, which will also be held in the backlog.
// This submission immediately follows the previous one, but force-processing
Expand All @@ -1132,7 +1144,7 @@ describe('Offline Entities', () => {

// Process submissions that have been in the backlog for a long time
// (only 1 of 2 should be processed)
const count = await container.Entities.processBacklog();
count = await container.Entities.processBacklog();
count.should.equal(1);

await asAlice.get('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc')
Expand Down

0 comments on commit 4dd1fca

Please sign in to comment.