From a08fb47413eb63cc2b470716ea3528d758b7b5d9 Mon Sep 17 00:00:00 2001 From: Joe Clark Date: Wed, 21 Aug 2024 14:46:07 +0100 Subject: [PATCH] worker: update cli docs and help --- .changeset/grumpy-knives-drop.md | 5 +++++ packages/ws-worker/src/api/destroy.ts | 2 +- packages/ws-worker/src/server.ts | 8 ++++---- packages/ws-worker/src/util/cli.ts | 9 +++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .changeset/grumpy-knives-drop.md diff --git a/.changeset/grumpy-knives-drop.md b/.changeset/grumpy-knives-drop.md new file mode 100644 index 000000000..f082ad4b2 --- /dev/null +++ b/.changeset/grumpy-knives-drop.md @@ -0,0 +1,5 @@ +--- +'@openfn/ws-worker': patch +--- + +Update CLI docs diff --git a/packages/ws-worker/src/api/destroy.ts b/packages/ws-worker/src/api/destroy.ts index f5102bedf..3f2295c47 100644 --- a/packages/ws-worker/src/api/destroy.ts +++ b/packages/ws-worker/src/api/destroy.ts @@ -61,7 +61,7 @@ const waitForRuns = (app: ServerApp, logger: Logger) => log(); app.events.on(INTERNAL_RUN_COMPLETE, onRunComplete); } else { - logger.debug('No active rns detected'); + logger.debug('No active runs detected, closing immediately'); resolve(); } }); diff --git a/packages/ws-worker/src/server.ts b/packages/ws-worker/src/server.ts index da879a779..5012aace3 100644 --- a/packages/ws-worker/src/server.ts +++ b/packages/ws-worker/src/server.ts @@ -93,13 +93,13 @@ function connect(app: ServerApp, logger: Logger, options: ServerOptions = {}) { options.maxWorkflows ); } else { + // @ts-ignore + const port = app.server?.address().port; logger.break(); - logger.warn('Workloop not starting'); + logger.warn('Noloop active: workloop has not started'); logger.info('This server will not auto-pull work from lightning.'); logger.info('You can manually claim by posting to /claim, eg:'); - logger.info( - ` curl -X POST http://locahost:${options.port || DEFAULT_PORT}/claim` - ); + logger.info(` curl -X POST http://localhost:${port}/claim`); logger.break(); } }; diff --git a/packages/ws-worker/src/util/cli.ts b/packages/ws-worker/src/util/cli.ts index 1a634d961..03418ffd3 100644 --- a/packages/ws-worker/src/util/cli.ts +++ b/packages/ws-worker/src/util/cli.ts @@ -2,6 +2,9 @@ import yargs from 'yargs'; import { LogLevel } from '@openfn/logger'; import { hideBin } from 'yargs/helpers'; +const DEFAULT_PORT = 2222; +const DEFAULT_WORKER_CAPACITY = 5; + type Args = { _: string[]; port?: number; @@ -64,6 +67,7 @@ export default function parseArgs(argv: string[]): Args { alias: 'p', description: 'Port to run the server on. Env: WORKER_PORT', type: 'number', + default: DEFAULT_PORT, }) .option('lightning', { alias: ['l', 'lightning-service-url'], @@ -105,6 +109,7 @@ export default function parseArgs(argv: string[]): Args { .option('capacity', { description: 'max concurrent workers. Env: WORKER_CAPACITY', type: 'number', + default: DEFAULT_WORKER_CAPACITY, }) .option('state-props-to-remove', { description: @@ -132,7 +137,7 @@ export default function parseArgs(argv: string[]): Args { return { ...args, - port: setArg(args.port, WORKER_PORT, 2222), + port: setArg(args.port, WORKER_PORT, DEFAULT_PORT), lightning: setArg( args.lightning, WORKER_LIGHTNING_SERVICE_URL, @@ -146,7 +151,7 @@ export default function parseArgs(argv: string[]): Args { ), log: setArg(args.log, WORKER_LOG_LEVEL as LogLevel, 'debug'), backoff: setArg(args.backoff, WORKER_BACKOFF, '1/10'), - capacity: setArg(args.capacity, WORKER_CAPACITY, 5), + capacity: setArg(args.capacity, WORKER_CAPACITY, DEFAULT_WORKER_CAPACITY), statePropsToRemove: setArg( args.statePropsToRemove, WORKER_STATE_PROPS_TO_REMOVE,