Skip to content

Commit 490c506

Browse files
authored
Update options script to reliably fetch options (#521)
2 parents e1b85a9 + 3553f49 commit 490c506

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "dist/index.js",
77
"scripts": {
88
"build:sql": "node scripts/buildSqlModule.mjs",
9-
"website:update": "node scripts/options.mjs",
9+
"website:update": "yarn prepack && node scripts/options.mjs",
1010
"prepack": "rm -Rf dist && npm run build:sql && tsc && chmod +x dist/cli.js",
1111
"watch": "mkdir -p dist && touch dist/cli.js && chmod +x dist/cli.js && npm run build:sql && tsc --watch",
1212
"lint": "yarn prettier:check && eslint --ext .js,.jsx,.ts,.tsx,.graphql .",

scripts/options.mjs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
#!/usr/bin/env zx
2+
// @ts-check
23
import "zx/globals";
4+
35
import * as fs from "fs/promises";
46

5-
// Create a symlink so `import "graphile-worker"` works
6-
await $`ln -s .. node_modules/graphile-worker || true`;
7+
await $`yarn link`;
8+
9+
// Create a temporary instance so we can read the options
10+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "gwdu-"));
11+
const prev = process.cwd();
12+
cd(tmp);
13+
await $`yarn link graphile-worker`;
14+
await $`yarn add typescript graphile`;
15+
await fs.writeFile(
16+
`graphile.config.ts`,
17+
`\
18+
import type {} from "graphile-worker";
19+
20+
const preset: GraphileConfig.Preset = {
21+
worker: {},
22+
};
23+
24+
export default preset;
25+
`,
26+
);
727

828
// Get the markdown output for options
929
const output = await $`graphile config options`;
1030

31+
// Go back and destroy our tempdir
32+
cd(prev);
33+
// Remove our temporary directory
34+
await fs.rm(tmp, { recursive: true, force: true });
35+
1136
// Crop it down to only include the stuff under the worker header
1237
const SEARCH = "\n## worker\n";
1338
const i = output.stdout.indexOf(SEARCH);
1439
if (i < 0) {
1540
throw new Error("Worker heading not found!");
1641
}
17-
const optionsMd = output.stdout.slice(i + SEARCH.length).trim();
42+
const optionsMd = output.stdout
43+
.slice(i + SEARCH.length)
44+
.trim()
45+
.replace(/\(https:\/\/worker\.graphile\.org\//g, "(/");
1846

1947
// Load the config.md doc file and replace the part between the comment tags
2048
const configMd = await fs.readFile("website/docs/config.md", "utf8");

src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ declare global {
5858
namespace GraphileConfig {
5959
interface WorkerOptions {
6060
/**
61-
* Database connection string.
61+
* Database [connection string](https://worker.graphile.org/docs/connection-string).
6262
*
6363
* @defaultValue `process.env.DATABASE_URL`
6464
*/
6565
connectionString?: string;
6666
/**
67-
* Maximum number of concurrent connections to Postgres
67+
* Maximum number of concurrent connections to Postgres; must be at least
68+
* `2`. This number can be lower than `concurrentJobs`, however a low
69+
* pool size may cause issues - if all your pool clients are busy then no
70+
* jobs can be started or released. If in doubt, we recommend setting it
71+
* to `10` or `concurrentJobs + 2`, whichever is larger. (Note: if your
72+
* task executors use this pool, then an even larger value may be needed
73+
* for optimum performance, depending on the shape of your logic.)
6874
*
6975
* @defaultValue `10`
7076
*/
@@ -153,6 +159,11 @@ declare global {
153159
*/
154160
logger?: Logger;
155161

162+
/**
163+
* A Node.js `EventEmitter` that exposes certain events within the runner
164+
* (see
165+
* [`WorkerEvents`](https://worker.graphile.org/docs/worker-events)).
166+
*/
156167
events?: WorkerEvents;
157168
}
158169
interface Preset {

website/docs/config.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Here are the options under the `worker` key as defined by
8080
crontabFile?: string;
8181
events?: WorkerEvents;
8282
fileExtensions?: string[];
83+
getQueueNameBatchDelay?: number;
8384
gracefulShutdownAbortTimeout?: number;
8485
logger?: Logger<{}>;
8586
maxPoolSize?: number;
@@ -103,7 +104,7 @@ Number of jobs to run concurrently.
103104

104105
Type: `string | undefined`
105106

106-
Database [connection string](./connection-string.md).
107+
Database [connection string](/docs/connection-string).
107108

108109
### worker.crontabFile
109110

@@ -126,6 +127,16 @@ A list of file extensions (in priority order) that Graphile Worker should
126127
attempt to import directly when loading tasks. Defaults to
127128
`[".js", ".cjs", ".mjs"]`.
128129

130+
### worker.getQueueNameBatchDelay
131+
132+
Type: `number | undefined`
133+
134+
**Experimental**
135+
136+
When getting a queue name in a job, we batch calls for efficiency. By default we
137+
do this over a 50ms window; increase this for greater efficiency, reduce this to
138+
reduce the latency for getting an individual queue name.
139+
129140
### worker.gracefulShutdownAbortTimeout
130141

131142
Type: `number | undefined`

0 commit comments

Comments
 (0)