Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions athena/queues/new-message-in-thread/buffer-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,26 @@ const bufferMessageNotificationEmail = async (
thread.id
}`
);
const job = await bufferNewMessageEmailQueue.getJob(recipient.email);
let job = await bufferNewMessageEmailQueue.getJob(recipient.email);
// Try to remove the job if it exists. This fails sometimes due to a
// race condition where the getJob returns a failed or active job.
// We circumvent that issue by simply pretending like no job exists
// and adding a new one
// Ref: withspectrum/spectrum#3189
if (job) {
debug(`timeout exists for ${recipient.email}, clearing`);
try {
await job.remove();
} catch (err) {
try {
await job.finished();
// Note(@mxstbr): This throws if the job fails to complete
// but we don't care if that happens, so we ignore it
} catch (err) {}

job = null;
}
}
if (!job) {
debug(
`creating new timeout for ${
Expand All @@ -185,9 +204,6 @@ const bufferMessageNotificationEmail = async (
);
} else {
const timeout = job.data;
// If we already have a timeout going
debug(`timeout exists for ${recipient.email}, clearing`);
await job.remove();
debug(`adding new thread to ${recipient.email}'s threads`);
timeout.threads.push(thread);
timeout.notifications.push(notification);
Expand Down
1 change: 1 addition & 0 deletions shared/bull/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type Job<JobData> = {|
id: string,
data: JobData,
remove: () => Promise<void>,
finished: () => Promise<void>,
|};

type JobOptions = {|
Expand Down