New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(api): Cancel all jobs related to a transactionId from the 'cancel' method #4616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ describe('Trigger event - Delay triggered events - /v1/events/trigger (POST)', f | |
let standardQueueService: StandardQueueService; | ||
const messageRepository = new MessageRepository(); | ||
|
||
const triggerEvent = async (payload, transactionId?: string, overrides = {}) => { | ||
const triggerEvent = async (payload, transactionId?: string, overrides = {}, to = [subscriber.subscriberId]) => { | ||
await axiosInstance.post( | ||
`${session.serverUrl}/v1/events/trigger`, | ||
{ | ||
transactionId, | ||
name: template.triggers[0].identifier, | ||
to: [subscriber.subscriberId], | ||
to, | ||
payload, | ||
overrides, | ||
}, | ||
|
@@ -330,6 +330,8 @@ describe('Trigger event - Delay triggered events - /v1/events/trigger (POST)', f | |
}); | ||
|
||
it('should be able to cancel delay', async function () { | ||
const secondSubscriber = await subscriberService.createSubscriber(); | ||
|
||
const id = MessageRepository.createObjectId(); | ||
template = await session.createTemplate({ | ||
steps: [ | ||
|
@@ -342,7 +344,7 @@ describe('Trigger event - Delay triggered events - /v1/events/trigger (POST)', f | |
content: '', | ||
metadata: { | ||
unit: DigestUnitEnum.SECONDS, | ||
amount: 0.1, | ||
amount: 5, | ||
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. To avoid flakiness in the test |
||
type: DelayTypeEnum.REGULAR, | ||
}, | ||
}, | ||
|
@@ -357,17 +359,19 @@ describe('Trigger event - Delay triggered events - /v1/events/trigger (POST)', f | |
{ | ||
customVar: 'Testing of User Name', | ||
}, | ||
id | ||
id, | ||
{}, | ||
[subscriber.subscriberId, secondSubscriber.subscriberId] | ||
); | ||
|
||
await session.awaitRunningJobs(template?._id, true, 1); | ||
await session.awaitRunningJobs(template?._id, true, 2); | ||
await axiosInstance.delete(`${session.serverUrl}/v1/events/trigger/${id}`, { | ||
headers: { | ||
authorization: `ApiKey ${session.apiKey}`, | ||
}, | ||
}); | ||
|
||
let delayedJob = await jobRepository.findOne({ | ||
let delayedJobs = await jobRepository.find({ | ||
_environmentId: session.environment._id, | ||
_templateId: template._id, | ||
type: StepTypeEnum.DELAY, | ||
|
@@ -380,14 +384,15 @@ describe('Trigger event - Delay triggered events - /v1/events/trigger (POST)', f | |
transactionId: id, | ||
}); | ||
|
||
expect(pendingJobs).to.equal(1); | ||
expect(pendingJobs).to.equal(2); | ||
|
||
delayedJob = await jobRepository.findOne({ | ||
delayedJobs = await jobRepository.find({ | ||
_environmentId: session.environment._id, | ||
_templateId: template._id, | ||
type: StepTypeEnum.DELAY, | ||
transactionId: id, | ||
}); | ||
expect(delayedJob!.status).to.equal(JobStatusEnum.CANCELED); | ||
expect(delayedJobs[0]!.status).to.equal(JobStatusEnum.CANCELED); | ||
expect(delayedJobs[1]!.status).to.equal(JobStatusEnum.CANCELED); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,20 +7,25 @@ export class CancelDelayed { | |
constructor(private jobRepository: JobRepository) {} | ||
|
||
public async execute(command: CancelDelayedCommand): Promise<boolean> { | ||
const job = await this.jobRepository.findOne({ | ||
_environmentId: command.environmentId, | ||
transactionId: command.transactionId, | ||
status: JobStatusEnum.DELAYED, | ||
}); | ||
const jobs = await this.jobRepository.find( | ||
{ | ||
_environmentId: command.environmentId, | ||
transactionId: command.transactionId, | ||
status: JobStatusEnum.DELAYED, | ||
}, | ||
'_id' | ||
); | ||
Comment on lines
+10
to
+17
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. it will still find only the delay job - as its the only one that has DELAYED status. The others are pending. Or am I missing something? 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. Never mind. Got you. its multiple subscribers |
||
|
||
if (!job) { | ||
if (!jobs?.length) { | ||
return false; | ||
} | ||
|
||
await this.jobRepository.update( | ||
{ | ||
_environmentId: command.environmentId, | ||
_id: job._id, | ||
_id: { | ||
$in: jobs.map((job) => job._id), | ||
}, | ||
}, | ||
{ | ||
$set: { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Added the ability to test more than 1 subscriber