Skip to content

Commit

Permalink
Skip executing tasks already marked as completed (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth authored May 16, 2024
1 parent 5a4e565 commit eaadfe6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ yargs(process.argv.slice(2))
if (receiveMessageResponse.Messages?.length) {
const message = receiveMessageResponse.Messages[0];
const body = Task.parse(JSON.parse(message.Body!));
const taskCompletionStatus = await checkTaskCompletionStatus(ctx, job.id, body.id);
if (taskCompletionStatus === "COMPLETED") {
console.log(`Task ${body.id} already completed, skipping.`);
continue;
}
const command = [...args.worker, body.id];
let visibilityTimeoutHandle = setInterval(async () => {
await updateMessageVisibilityTimeout(
Expand Down Expand Up @@ -297,6 +302,23 @@ async function getPreviouslyRunTaskStatuses(
return response;
}

async function checkTaskCompletionStatus(
{ dynamodbClient }: Context,
jobId: string,
taskId: string
): Promise<string> {
const response = await dynamodbClient.send(
new dynamodb.GetItemCommand({
TableName: env.PARALLELIZER_DYNAMODB_TABLE,
Key: {
TaskListId: { S: jobId },
TaskId: { S: taskId },
},
})
);
return response.Item?.Status?.S || "PENDING";
}

async function updateTaskStatusInDynamoDB(
{ dynamodbClient }: Context,
jobId: string,
Expand Down

0 comments on commit eaadfe6

Please sign in to comment.