@output.ai/core 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/worker.sh
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineQuery, setHandler } from '@temporalio/workflow';
|
|
1
|
+
import { defineQuery, setHandler, condition } from '@temporalio/workflow';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a special workflow, unique to each worker, which holds the meta information of all other workflows in that worker.
|
|
@@ -9,5 +9,6 @@ import { defineQuery, setHandler } from '@temporalio/workflow';
|
|
|
9
9
|
*/
|
|
10
10
|
export default async function catalogWorkflow( catalog ) {
|
|
11
11
|
setHandler( defineQuery( 'get' ), () => catalog );
|
|
12
|
-
|
|
12
|
+
// Wait indefinitely but remain responsive to workflow cancellation
|
|
13
|
+
await condition( () => false );
|
|
13
14
|
};
|
package/src/worker/index.js
CHANGED
|
@@ -56,5 +56,39 @@ const callerDir = process.argv[2];
|
|
|
56
56
|
} );
|
|
57
57
|
|
|
58
58
|
console.log( '[Core]', 'Running worker...' );
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
|
|
60
|
+
// FORCE_QUIT_GRACE_MS delays the second instance of a shutdown command.
|
|
61
|
+
// If running output-worker directly with npx, 2 signals are recieved in
|
|
62
|
+
// rapid succession, and users see the force quit message.
|
|
63
|
+
const FORCE_QUIT_GRACE_MS = 1000;
|
|
64
|
+
const state = { isShuttingDown: false, shutdownStartedAt: null };
|
|
65
|
+
|
|
66
|
+
const shutdown = signal => {
|
|
67
|
+
if ( state.isShuttingDown ) {
|
|
68
|
+
const elapsed = Date.now() - state.shutdownStartedAt;
|
|
69
|
+
if ( elapsed < FORCE_QUIT_GRACE_MS ) {
|
|
70
|
+
return; // ignore rapid duplicate signals
|
|
71
|
+
}
|
|
72
|
+
process.stderr.write( '[Core] Force quitting...\n' );
|
|
73
|
+
process.exit( 1 );
|
|
74
|
+
}
|
|
75
|
+
state.isShuttingDown = true;
|
|
76
|
+
state.shutdownStartedAt = Date.now();
|
|
77
|
+
process.stderr.write( `[Core] Received ${signal}, shutting down...\n` );
|
|
78
|
+
worker.shutdown();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
process.on( 'SIGTERM', () => shutdown( 'SIGTERM' ) );
|
|
82
|
+
process.on( 'SIGINT', () => shutdown( 'SIGINT' ) );
|
|
83
|
+
|
|
84
|
+
await worker.run();
|
|
85
|
+
process.stderr.write( '[Core] Worker stopped.\n' );
|
|
86
|
+
|
|
87
|
+
await connection.close();
|
|
88
|
+
process.stderr.write( '[Core] Connection closed.\n' );
|
|
89
|
+
|
|
90
|
+
process.exit( 0 );
|
|
91
|
+
} )().catch( error => {
|
|
92
|
+
process.stderr.write( `[Core] Fatal error: ${error.message}\n` );
|
|
93
|
+
process.exit( 1 );
|
|
94
|
+
} );
|