Skip to content

Commit

Permalink
better heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Aug 27, 2023
1 parent 12efa21 commit a1dda74
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
14 changes: 13 additions & 1 deletion dist/worker-wrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/worker-wrapper.js.map

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion dist/worker-wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,19 @@ var Worker = class {
type: "ava-postgres",
message: "running postgres heartbeat..."
});
const { rows } = await postgresClient.query("SELECT 1");
const { rows } = await Promise.race([
postgresClient.query("SELECT 1"),
new Promise(
(_, reject) => setTimeout(
() => reject(
new Error(
"postgres heartbeat timed out after 6 seconds (query took too long)"
)
),
6e3
)
)
]);
parentPort.postMessage({
type: "ava-postgres",
message: "postgres heartbeat success",
Expand Down
2 changes: 1 addition & 1 deletion dist/worker-wrapper.mjs.map

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,20 @@ export class Worker {
message: "running postgres heartbeat...",
})

const { rows } = await postgresClient.query("SELECT 1")
const { rows } = await Promise.race([
postgresClient.query("SELECT 1"),
new Promise<never>((_, reject) =>
setTimeout(
() =>
reject(
new Error(
"postgres heartbeat timed out after 6 seconds (query took too long)"
)
),
6000
)
),
])

parentPort!.postMessage({
type: "ava-postgres",
Expand Down

0 comments on commit a1dda74

Please sign in to comment.