File tree 5 files changed +41
-29
lines changed
5 files changed +41
-29
lines changed Original file line number Diff line number Diff line change 1
- // import "graphile-config";
1
+ // @ts -check
2
2
3
- // import { WorkerProPreset } from "../graphile-pro-worker/ dist/index.js";
3
+ /** @typedef { import( "../dist/index.js") } Worker */
4
4
// import type {} from "../src/index.js";
5
5
6
+ // import { WorkerProPreset } from "../graphile-pro-worker/dist/index.js";
7
+
6
8
/** @type {GraphileConfig.Preset } */
7
9
const preset = {
8
10
// extends: [WorkerProPreset],
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ // @ts -check
1
2
const assert = require ( "assert" ) ;
2
3
const { Pool } = require ( "pg" ) ;
3
4
const { runTaskList } = require ( "../dist/main" ) ;
4
5
const { default : deferred } = require ( "../dist/deferred" ) ;
6
+ const preset = require ( "./graphile.config.js" ) ;
5
7
8
+ /** @type {(ms: number) => Promise<void> } */
6
9
const sleep = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
7
10
11
+ /** @type {import('../dist/index.js').WorkerPoolOptions } */
8
12
const options = {
9
13
concurrency : 1 ,
14
+ preset,
10
15
} ;
11
16
12
17
async function main ( ) {
13
18
const pgPool = new Pool ( { connectionString : process . env . PERF_DATABASE_URL } ) ;
14
19
const startTimes = { } ;
15
20
let latencies = [ ] ;
16
21
const deferreds = { } ;
22
+ /** @type {import('../dist/index.js').TaskList } */
17
23
const tasks = {
18
24
latency : ( { id } ) => {
19
25
latencies . push ( process . hrtime ( startTimes [ id ] ) ) ;
@@ -86,6 +92,7 @@ main().catch((e) => {
86
92
process . exit ( 1 ) ;
87
93
} ) ;
88
94
95
+ /** @type {(pgPool: Pool) => Promise<void> } */
89
96
async function forEmptyQueue ( pgPool ) {
90
97
let remaining ;
91
98
do {
Original file line number Diff line number Diff line change @@ -50,9 +50,14 @@ async function main() {
50
50
console . log ( ) ;
51
51
console . log ( ) ;
52
52
console . log ( "Timing startup/shutdown time..." ) ;
53
- const startupTime = await time ( ( ) => {
54
- execSync ( "node ../dist/cli.js --once" , execOptions ) ;
53
+ let result ;
54
+ const startupTime = await time ( async ( ) => {
55
+ result = await exec (
56
+ `node ../dist/cli.js --once -j ${ CONCURRENCY } -m ${ CONCURRENCY + 1 } ` ,
57
+ execOptions ,
58
+ ) ;
55
59
} ) ;
60
+ logResult ( result ) ;
56
61
console . log ( ) ;
57
62
58
63
if ( STUCK_JOB_COUNT > 0 ) {
@@ -83,17 +88,7 @@ async function main() {
83
88
) ,
84
89
) ;
85
90
}
86
- ( await Promise . all ( promises ) ) . map ( ( { error, stdout, stderr } ) => {
87
- if ( error ) {
88
- throw error ;
89
- }
90
- if ( stdout ) {
91
- console . log ( stdout ) ;
92
- }
93
- if ( stderr ) {
94
- console . error ( stderr ) ;
95
- }
96
- } ) ;
91
+ ( await Promise . all ( promises ) ) . map ( logResult ) ;
97
92
} ) ;
98
93
console . log (
99
94
`Jobs per second: ${ ( ( 1000 * JOB_COUNT ) / ( dur - startupTime ) ) . toFixed ( 2 ) } ` ,
@@ -112,3 +107,15 @@ main().catch((e) => {
112
107
console . error ( e ) ;
113
108
process . exit ( 1 ) ;
114
109
} ) ;
110
+
111
+ function logResult ( { error, stdout, stderr } ) {
112
+ if ( error ) {
113
+ throw error ;
114
+ }
115
+ if ( stdout ) {
116
+ console . log ( stdout ) ;
117
+ }
118
+ if ( stderr ) {
119
+ console . error ( stderr ) ;
120
+ }
121
+ }
Original file line number Diff line number Diff line change
1
+ declare global {
2
+ namespace GraphileWorker {
3
+ interface Tasks {
4
+ latency : { id : number } ;
5
+ }
6
+ }
7
+ }
8
+
9
+ // Has to be a module, so export something
10
+ export type Foo = "Foo" ;
You can’t perform that action at this time.
0 commit comments