JobQueue: Allow jobs to be added before streaming starts
This commit is contained in:
parent
2394a25fc1
commit
ca92068664
4 changed files with 48 additions and 26 deletions
|
@ -25,22 +25,23 @@ describe('JobQueueDatabaseStore', () => {
|
|||
});
|
||||
|
||||
describe('insert', () => {
|
||||
it("fails if streaming hasn't started yet", async () => {
|
||||
it("adds jobs to database even if streaming hasn't started yet", async () => {
|
||||
const store = new JobQueueDatabaseStore(fakeDatabase);
|
||||
|
||||
let error: unknown;
|
||||
try {
|
||||
await store.insert({
|
||||
id: 'abc',
|
||||
timestamp: 1234,
|
||||
queueType: 'test queue',
|
||||
data: { hi: 5 },
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
error = err;
|
||||
}
|
||||
await store.insert({
|
||||
id: 'abc',
|
||||
timestamp: 1234,
|
||||
queueType: 'test queue',
|
||||
data: { hi: 5 },
|
||||
});
|
||||
|
||||
assert.instanceOf(error, Error);
|
||||
sinon.assert.calledOnce(fakeDatabase.insertJob);
|
||||
sinon.assert.calledWithMatch(fakeDatabase.insertJob, {
|
||||
id: 'abc',
|
||||
timestamp: 1234,
|
||||
queueType: 'test queue',
|
||||
data: { hi: 5 },
|
||||
});
|
||||
});
|
||||
|
||||
it('adds jobs to the database', async () => {
|
||||
|
@ -153,6 +154,26 @@ describe('JobQueueDatabaseStore', () => {
|
|||
sinon.assert.calledOnce(fakeDatabase.insertJob);
|
||||
assert.deepEqual(events, ['loaded jobs', 'insert']);
|
||||
});
|
||||
|
||||
it("adds jobs if we haven't started streaming at all", async () => {
|
||||
const events: Array<string> = [];
|
||||
|
||||
fakeDatabase.insertJob.callsFake(() => {
|
||||
events.push('insert');
|
||||
});
|
||||
|
||||
const store = new JobQueueDatabaseStore(fakeDatabase);
|
||||
|
||||
await store.insert({
|
||||
id: 'abc',
|
||||
timestamp: 1234,
|
||||
queueType: 'test queue',
|
||||
data: { hi: 5 },
|
||||
});
|
||||
|
||||
sinon.assert.calledOnce(fakeDatabase.insertJob);
|
||||
assert.deepEqual(events, ['insert']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete', () => {
|
||||
|
|
|
@ -838,7 +838,7 @@ describe('JobQueue', () => {
|
|||
});
|
||||
|
||||
describe('add', () => {
|
||||
it('rejects if the job queue has not started streaming', async () => {
|
||||
it('adds even if the job queue has not started streaming', async () => {
|
||||
const fakeStore = {
|
||||
insert: sinon.stub().resolves(),
|
||||
delete: sinon.stub().resolves(),
|
||||
|
@ -861,7 +861,7 @@ describe('JobQueue', () => {
|
|||
maxAttempts: 99,
|
||||
});
|
||||
|
||||
await assert.isRejected(noopQueue.add(undefined));
|
||||
await noopQueue.add(undefined);
|
||||
|
||||
sinon.assert.notCalled(fakeStore.stream as sinon.SinonStub);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue