-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-generic): implement memory db and redo queues and workers
- Loading branch information
1 parent
8223aff
commit 58c46d7
Showing
124 changed files
with
10,782 additions
and
15,717 deletions.
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
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
94 changes: 94 additions & 0 deletions
94
apps/api/src/app/events/services/events-workflow-queue.service.spec.ts
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
|
||
import { EventsWorkflowQueueService } from './events-workflow-queue.service'; | ||
|
||
let eventsWorkflowQueueService: EventsWorkflowQueueService; | ||
|
||
describe('EventsWorkflowQueue service', () => { | ||
beforeEach(async () => { | ||
eventsWorkflowQueueService = new EventsWorkflowQueueService(); | ||
await eventsWorkflowQueueService.queue.obliterate(); | ||
}); | ||
|
||
after(async () => { | ||
await eventsWorkflowQueueService.gracefulShutdown(); | ||
}); | ||
|
||
it('should be initialised properly', async () => { | ||
expect(eventsWorkflowQueueService).to.exist; | ||
expect(Object.keys(eventsWorkflowQueueService)).to.include.members([ | ||
'name', | ||
'queue', | ||
'DEFAULT_ATTEMPTS', | ||
'instance', | ||
]); | ||
expect(eventsWorkflowQueueService.name).to.equal('trigger-handler'); | ||
expect(await eventsWorkflowQueueService.bullMqService.getRunningStatus()).to.deep.equal({ | ||
queueIsPaused: false, | ||
queueName: 'trigger-handler', | ||
workerName: undefined, | ||
workerIsRunning: undefined, | ||
}); | ||
expect(eventsWorkflowQueueService.queue).to.deep.include({ | ||
_events: {}, | ||
_eventsCount: 0, | ||
_maxListeners: undefined, | ||
name: 'trigger-handler', | ||
jobsOpts: { | ||
removeOnComplete: true, | ||
}, | ||
}); | ||
expect(eventsWorkflowQueueService.queue.opts).to.deep.include({ | ||
blockingConnection: false, | ||
connection: { | ||
connectTimeout: 50000, | ||
db: 1, | ||
family: 4, | ||
host: 'localhost', | ||
keepAlive: 7200, | ||
keyPrefix: '', | ||
password: undefined, | ||
port: 6379, | ||
tls: undefined, | ||
}, | ||
defaultJobOptions: { | ||
removeOnComplete: true, | ||
}, | ||
prefix: 'bull', | ||
sharedConnection: false, | ||
}); | ||
expect(eventsWorkflowQueueService.queue.opts.connection).to.deep.include({ | ||
host: 'localhost', | ||
port: 6379, | ||
}); | ||
}); | ||
|
||
it('should add a job in the queue', async () => { | ||
const jobId = 'events-workflow-job-id'; | ||
const _environmentId = 'events-workflow-environment-id'; | ||
const _organizationId = 'events-workflow-organization-id'; | ||
const _userId = 'events-workflow-user-id'; | ||
const jobData = { | ||
_id: jobId, | ||
test: 'events-workflow-job-data', | ||
_environmentId, | ||
_organizationId, | ||
_userId, | ||
}; | ||
await eventsWorkflowQueueService.add(jobId, jobData, _organizationId); | ||
|
||
expect(await eventsWorkflowQueueService.queue.getActiveCount()).to.equal(0); | ||
expect(await eventsWorkflowQueueService.queue.getWaitingCount()).to.equal(1); | ||
|
||
const eventsWorkflowQueueJobs = await eventsWorkflowQueueService.queue.getJobs(); | ||
expect(eventsWorkflowQueueJobs.length).to.equal(1); | ||
const [eventsWorkflowQueueJob] = eventsWorkflowQueueJobs; | ||
expect(eventsWorkflowQueueJob).to.deep.include({ | ||
id: '1', | ||
name: jobId, | ||
data: jobData, | ||
attemptsMade: 0, | ||
}); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
apps/api/src/app/events/services/events-workflow-queue.service.ts
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { WorkflowQueueService } from '@novu/application-generic'; | ||
|
||
@Injectable() | ||
export class EventsWorkflowQueueService extends WorkflowQueueService {} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { EventsWorkflowQueueService } from './events-workflow-queue.service'; |
Oops, something went wrong.