Skip to content

Commit da12151

Browse files
committed
chore: debug problems with worker getting stuck
Squashed commit of the following: commit 0e7f1c7e85bcb7dbfdc737e5e12cc59315ea13a3 Author: Wojtek Majewski <[email protected]> Date: Wed Jan 22 16:18:51 2025 +0100 chore(deps): update deno.lock with p-queue dependency Add npm p-queue package to project dependencies Update lock file with new package and its transitive dependencies commit aa17c507bb840461e0ca2a55795d27ec044098e2 Author: Wojtek Majewski <[email protected]> Date: Wed Jan 22 16:18:28 2025 +0100 refactor(executor): Simplify message execution and error handling Modify message execution flow to use direct signal abort check and update archiving method. Remove complex Promise.race implementation in favor of a more straightforward execution approach. commit 6c1b1c278319951b6e1814ab5a056da7226cc4ef Author: Wojtek Majewski <[email protected]> Date: Wed Jan 22 16:15:47 2025 +0100 refactor(edge-worker): Adjust max concurrency and delay settings Modify max concurrent workers and randomize delay time for test sequence increment to improve worker behavior and testing
1 parent 97b7e3e commit da12151

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

pkgs/edge-worker/deno.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/edge-worker/src/MessageExecutor.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,16 @@ export class MessageExecutor<MessagePayload extends Json> {
3939
throw new AbortError();
4040
}
4141

42-
await Promise.race([
43-
this.messageHandler(this.record.message!),
44-
new Promise((_, reject) => {
45-
this.signal.addEventListener(
46-
'abort',
47-
() => {
48-
console.log(
49-
`################ MessageExecutor aborted during execution: ${this.msgId} ##`
50-
);
51-
reject(new AbortError());
52-
},
53-
{ once: true }
54-
);
55-
}),
56-
]);
42+
// Check if already aborted before starting
43+
this.signal.throwIfAborted();
44+
45+
await this.messageHandler(this.record.message!);
5746

5847
console.log(
5948
`[MessageExecutor] Task ${this.msgId} completed successfully, archiving...`
6049
);
61-
await this.batchArchiver.add(this.msgId);
50+
await this.queue.archive(this.msgId);
51+
// await this.batchArchiver.add(this.msgId);
6252
} catch (error) {
6353
await this.handleExecutionError(error);
6454
}

pkgs/edge-worker/supabase/functions/max_concurrency/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ console.log('EDGE_WORKER_DB_URL', EDGE_WORKER_DB_URL);
88
const sql = postgres(EDGE_WORKER_DB_URL, { prepare: true });
99

1010
async function incrementSeq() {
11-
await delay(100);
12-
// const randTimeMs = Math.floor(Math.random() * 10);
13-
// await delay(randTimeMs);
11+
// await delay(1000);
12+
const randTimeMs = Math.floor(Math.random() * 100 + 50);
13+
await delay(randTimeMs);
1414
console.log(
1515
'[max_concurrency] last_val =',
1616
await sql`SELECT nextval('test_seq')`
@@ -19,6 +19,6 @@ async function incrementSeq() {
1919

2020
EdgeWorker.start(incrementSeq, {
2121
queueName: 'max_concurrency',
22-
maxConcurrent: 40,
22+
maxConcurrent: 10,
2323
maxPgConnections: 4,
2424
});

0 commit comments

Comments
 (0)