This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Clean up Jobqueues, minor fixes for S3 Queue #451
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,30 @@ describe('job queues', () => { | |
await waitForLogEntries(2) | ||
expect(testConsole.read()).toEqual([['processEvent'], ['reply', 'runIn']]) | ||
}) | ||
|
||
test('polls for jobs in future', async () => { | ||
const DELAY = 3000 // 3s | ||
|
||
// return something to be picked up after a few loops (poll interval is 100ms) | ||
const now = Date.now() | ||
|
||
const job: EnqueuedJob = { | ||
type: 'pluginJob', | ||
payload: { key: 'value' }, | ||
timestamp: now + DELAY, | ||
pluginConfigId: 2, | ||
pluginConfigTeam: 3, | ||
} | ||
|
||
server.hub.jobQueueManager.enqueue(job) | ||
const consumedJob: EnqueuedJob = await new Promise((resolve, reject) => { | ||
server.hub.jobQueueManager.startConsumer((consumedJob) => { | ||
resolve(consumedJob[0]) | ||
}) | ||
}) | ||
|
||
expect(consumedJob).toEqual(job) | ||
}) | ||
}) | ||
|
||
describe('connection', () => { | ||
|
@@ -284,5 +308,44 @@ describe('job queues', () => { | |
Key: `prefix/2020-01-01/20200101-123456.123Z-deadbeef.json.gz`, | ||
}) | ||
}) | ||
|
||
test('polls for new jobs', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these tests would fail after 60s (jest timeout) if there's no polling. |
||
const DELAY = 10000 // 10s | ||
// calls the right functions to read the enqueued job | ||
mS3WrapperInstance.mockClear() | ||
|
||
// return something to be picked up after a few loops (poll interval is 5s) | ||
const now = Date.now() | ||
const date = new Date(now + DELAY).toISOString() | ||
const [day, time] = date.split('T') | ||
const dayTime = `${day.split('-').join('')}-${time.split(':').join('')}` | ||
|
||
const job: EnqueuedJob = { | ||
type: 'pluginJob', | ||
payload: { key: 'value' }, | ||
timestamp: now, | ||
pluginConfigId: 2, | ||
pluginConfigTeam: 3, | ||
} | ||
|
||
mS3WrapperInstance.listObjectsV2.mockReturnValue({ | ||
Contents: [{ Key: `prefix/${day}/${dayTime}-deadbeef.json.gz` }], | ||
}) | ||
mS3WrapperInstance.getObject.mockReturnValueOnce({ | ||
Body: gzipSync(Buffer.from(JSON.stringify(job), 'utf8')), | ||
}) | ||
|
||
const consumedJob: EnqueuedJob = await new Promise((resolve, reject) => { | ||
hub.jobQueueManager.startConsumer((consumedJob) => { | ||
resolve(consumedJob[0]) | ||
}) | ||
}) | ||
expect(consumedJob).toEqual(job) | ||
await delay(10) | ||
expect(mS3WrapperInstance.deleteObject).toBeCalledWith({ | ||
Bucket: 'bucket-name', | ||
Key: `prefix/${day}/${dayTime}-deadbeef.json.gz`, | ||
}) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resume is called on
drain
events emitted by Piscina, which results in multiple calls to sync state. This is okay, as long as dequeue code is idempotent (which it isn't, thus leading to race conditions).We didn't face this with graphile because the runner object is unchanged over multiple sync state calls.