Skip to content

Commit ef921cd

Browse files
committed
hook up new options to CLI
1 parent 93e025c commit ef921cd

4 files changed

Lines changed: 40 additions & 19 deletions

File tree

packages/ws-worker/src/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export type ServerOptions = {
5656
collectionsVersion?: string;
5757
collectionsUrl?: string;
5858
monorepoDir?: string;
59+
60+
timeoutRetryCount?: number;
61+
timeoutRetryDelayMs?: number;
5962
};
6063

6164
// this is the server/koa API
@@ -301,6 +304,9 @@ function createServer(engine: RuntimeEngine, options: ServerOptions = {}) {
301304
if (!('payloadLimitMb' in options)) {
302305
options.payloadLimitMb = app.options.payloadLimitMb;
303306
}
307+
options.timeoutRetryCount = app.options.timeoutRetryCount;
308+
options.timeoutRetryDelay =
309+
app.options.timeoutRetryDelayMs ?? app.options.socketTimeoutSeconds;
304310

305311
// Callback to be triggered when the work is done (including errors)
306312
const onFinish = () => {

packages/ws-worker/src/start.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ function engineReady(engine: any) {
4949
claimTimeoutSeconds: args.claimTimeoutSeconds,
5050
// deprecated!
5151
socketTimeoutSeconds: args.socketTimeoutSeconds,
52+
timeoutRetryCount: args.timeoutRetryCount,
53+
timeoutRetryDelayMs: args.timeoutRetryDelayMs,
5254
};
5355

5456
if ('socketTimeoutSeconds' in args) {

packages/ws-worker/src/util/cli.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ const DEFAULT_WORKER_CAPACITY = 5;
1212
type Args = {
1313
_: string[];
1414
backoff: string;
15-
debug?: boolean;
1615
capacity?: number;
16+
claimTimeoutSeconds?: number;
1717
collectionsUrl?: string;
1818
collectionsVersion?: string;
19-
engineValidationTimeoutMs?: number;
19+
debug?: boolean;
2020
engineValidationRetries?: number;
21+
engineValidationTimeoutMs?: number;
2122
lightning?: string;
2223
lightningPublicKey?: string;
2324
log?: LogLevel;
2425
loop?: boolean;
2526
maxRunDurationSeconds: number;
27+
messageTimeoutSeconds?: number;
2628
mock?: boolean;
2729
monorepoDir?: string;
2830
payloadMemory?: number;
@@ -32,12 +34,12 @@ type Args = {
3234
repoDir?: string;
3335
runMemory?: number;
3436
secret?: string;
35-
socketTimeoutSeconds?: number; // deprecated
36-
messageTimeoutSeconds?: number;
37-
claimTimeoutSeconds?: number;
38-
statePropsToRemove?: string[];
3937
sentryDsn?: string;
4038
sentryEnv?: string;
39+
socketTimeoutSeconds?: number; // deprecated
40+
statePropsToRemove?: string[];
41+
timeoutRetryCount?: number;
42+
timeoutRetryDelayMs?: number;
4143
};
4244

4345
type ArgTypes = string | string[] | number | boolean | undefined;
@@ -82,14 +84,16 @@ export default function parseArgs(argv: string[]): Args {
8284
WORKER_MAX_RUN_MEMORY_MB,
8385
WORKER_MESSAGE_TIMEOUT_SECONDS,
8486
WORKER_PORT,
85-
WORKER_PROFILE,
8687
WORKER_PROFILE_POLL_INTERVAL_MS,
88+
WORKER_PROFILE,
8789
WORKER_REPO_DIR,
8890
WORKER_SECRET,
8991
WORKER_SENTRY_DSN,
9092
WORKER_SENTRY_ENV,
9193
WORKER_SOCKET_TIMEOUT_SECONDS,
9294
WORKER_STATE_PROPS_TO_REMOVE,
95+
WORKER_TIMEOUT_RETRY_COUNT,
96+
WORKER_TIMEOUT_RETRY_DELAY_MS,
9397
WORKER_VALIDATION_RETRIES,
9498
WORKER_VALIDATION_TIMEOUT_MS,
9599
} = process.env;
@@ -219,6 +223,16 @@ export default function parseArgs(argv: string[]): Args {
219223
description:
220224
'Interval for polling profile data, in milliseconds. Default 10. Env: WORKER_PROFILE_POLL_INTERVAL_MS',
221225
type: 'number',
226+
})
227+
.option('timeout-retry-count', {
228+
description:
229+
'When a websocket event receives a timeout, this option sets how many times the worker should retry it. Default 10. Env: WORKER_TIMEOUT_RETRY_COUNT',
230+
type: 'number',
231+
})
232+
.option('timeout-retry-delay', {
233+
description:
234+
'When a websocket event receives a timeout, this option sets how log to wait before retrying Default 30000. Env: WORKER_TIMEOUT_RETRY_DELAY_MS',
235+
type: 'number',
222236
});
223237

224238
const args = parser.parse() as Args;
@@ -289,5 +303,15 @@ export default function parseArgs(argv: string[]): Args {
289303
WORKER_PROFILE_POLL_INTERVAL_MS,
290304
10
291305
),
306+
timeoutRetryCount: setArg(
307+
args.timeoutRetryCount,
308+
WORKER_TIMEOUT_RETRY_COUNT,
309+
10
310+
),
311+
timeoutRetryDelayMs: setArg(
312+
args.timeoutRetryDelayMs,
313+
WORKER_TIMEOUT_RETRY_DELAY_MS,
314+
30 * 1000
315+
),
292316
} as Args;
293317
}

packages/ws-worker/src/util/send-event.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ import * as Sentry from '@sentry/node';
22
import type { Context } from '../api/execute';
33
import { LightningSocketError, LightningTimeoutError } from '../errors';
44

5-
// // When a message receives a timeout, how many times should we retry?
6-
// const TIMEOUT_RETRY_COUNT = process.env.WORKER_TIMEOUT_RETRY_COUNT
7-
// ? parseInt(process.env.WORKER_TIMEOUT_RETRY_COUNT)
8-
// : 10;
9-
10-
// // When a message receives a timeout, how long should we wait before retrying?
11-
// const TIMEOUT_RETRY_DELAY =
12-
// process.env.WORKER_TIMEOUT_RETRY_DELAY ??
13-
// process.env.WORKER_MESSAGE_TIMEOUT_SECONDS ??
14-
// 30 * 1000;
15-
165
export const sendEvent = <T>(
176
context: Pick<Context, 'logger' | 'channel' | 'id' | 'options'>,
187
event: string,
@@ -63,7 +52,7 @@ export const sendEvent = <T>(
6352
report(new LightningTimeoutError(event));
6453
} else {
6554
logger.warn(
66-
`${runId} event ${event} timed out, will retry (attempt ${
55+
`${runId} event ${event} timed out, will retry in ${timeoutRetryDelay}ms (attempt ${
6756
thisAttempt + 1
6857
} of ${timeoutRetryCount})`
6958
);

0 commit comments

Comments
 (0)