Skip to content

Commit

Permalink
make error more obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed May 17, 2024
1 parent f3a2ec1 commit e916900
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as dynamodb from "@aws-sdk/client-dynamodb";
import os from "os";
import { z } from "zod";
import { Context } from "./createContext";
import { env } from "./env";
Expand Down Expand Up @@ -84,7 +83,7 @@ async function updateTaskStatusInDynamoDB(
status: string,
isStart: boolean
) {
const workerId = process.env.PARALLELIZER_WORKER_ID || os.hostname();
const workerId = env.PARALLELIZER_WORKER_ID;
const timestamp = new Date().toISOString();
let updateExpression =
"set #status = :status, #taskDisplayName = :taskDisplayName, #timestamp = :timestamp, #workerId = :workerId";
Expand Down
4 changes: 3 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { z } from "zod";
import { Env } from "@(-.-)/env";
import { hostname } from "os";
import { z } from "zod";

const envSchema = z.object({
PARALLELIZER_DYNAMODB_TABLE: z.string().default("parallelizer"),
PARALLELIZER_WORKER_ID: z.string().default(hostname()),
});

const env = Env(envSchema);
Expand Down
13 changes: 9 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ yargs(process.argv.slice(2))
VisibilityTimeout: 30,
})
);
let errorMessage = "";
if (receiveMessageResponse.Messages?.length) {
const message = receiveMessageResponse.Messages[0];
const body = Task.parse(JSON.parse(message.Body!));
Expand Down Expand Up @@ -163,7 +164,10 @@ yargs(process.argv.slice(2))
console.log(`::group::${title}`);
const durationTracker = createDurationTracker();
try {
await execa(command[0], command.slice(1), { stdio: "inherit" });
await execa(command[0], command.slice(1), {
stdio: "inherit",
env: { PARALLELIZER_TASK_ID: body.id },
});
await updateTaskStatusInDynamoDB(
ctx,
job.id,
Expand All @@ -177,9 +181,7 @@ yargs(process.argv.slice(2))
} catch (error) {
const duration = durationTracker.formatDuration();
console.log(`Task ${body.id} failed in ${duration}s`);
console.log(
`::error title=${body.displayName} (${body.id}) failed::${error}`
);
errorMessage = `::error title=${body.displayName} (${body.id}) failed::${error}`;
console.error("Error running command:", error);
process.exitCode = 1;
failed++;
Expand All @@ -192,6 +194,9 @@ yargs(process.argv.slice(2))
);
} finally {
console.log(`::endgroup::`);
if (errorMessage) {
console.log(errorMessage);
}
clearInterval(visibilityTimeoutHandle);
await sqsClient.send(
new sqs.DeleteMessageCommand({
Expand Down

0 comments on commit e916900

Please sign in to comment.