Skip to content

Commit

Permalink
fix: wrap chunk tasks as progress tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohn25 committed Aug 27, 2024
1 parent 2d0241c commit ec930d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/server/tasks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export interface ProgressTaskOptions {
removeOnComplete: boolean;
}

export type ProgressTaskList<P = unknown> = Record<string, ProgressTask<P>>;

export const wrapProgressTask = <P extends { [key: string]: any }>(
task: ProgressTask<P>,
options: ProgressTaskOptions
Expand Down Expand Up @@ -155,3 +157,14 @@ export const wrapProgressTask = <P extends { [key: string]: any }>(
throw err;
}
};

export const wrapProgressTaskList = async <P extends ProgressTaskPayload>(
list: ProgressTaskList<P>
) => {
return Object.entries(list).reduce((acc, [key, task]) => {
acc[key] = wrapProgressTask(task, {
removeOnComplete: true
});
return acc;
}, {} as ProgressTaskList<P>);
};
4 changes: 2 additions & 2 deletions src/server/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import syncContactQuestionResponse from "./tasks/sync-contact-question-response"
import syncSlackTeamMembers from "./tasks/sync-slack-team-members";
import { trollPatrol, trollPatrolForOrganization } from "./tasks/troll-patrol";
import updateOrgMessageUsage from "./tasks/update-org-message-usage";
import { wrapProgressTask } from "./tasks/utils";
import { wrapProgressTask, wrapProgressTaskList } from "./tasks/utils";

const logFactory: LogFunctionFactory = (scope) => (level, message, meta) =>
logger.log({ level, message, ...meta, ...scope });
Expand Down Expand Up @@ -110,7 +110,7 @@ export const getWorker = async (attempt = 0): Promise<Runner> => {
[exportOptOutsIdentifier]: exportOptOuts,
...ngpVanTaskList,
...campaignBuilderTaskList,
...chunkTaskList
...wrapProgressTaskList(chunkTaskList)
};

if (!workerSemaphore) {
Expand Down

0 comments on commit ec930d7

Please sign in to comment.