@sidequest/engine 1.0.0-next.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.
Files changed (81) hide show
  1. package/dist/engine.cjs +189 -0
  2. package/dist/engine.cjs.map +1 -0
  3. package/dist/engine.d.ts +122 -0
  4. package/dist/engine.js +187 -0
  5. package/dist/engine.js.map +1 -0
  6. package/dist/execution/dispatcher.cjs +90 -0
  7. package/dist/execution/dispatcher.cjs.map +1 -0
  8. package/dist/execution/dispatcher.d.ts +44 -0
  9. package/dist/execution/dispatcher.js +88 -0
  10. package/dist/execution/dispatcher.js.map +1 -0
  11. package/dist/execution/executor-manager.cjs +151 -0
  12. package/dist/execution/executor-manager.cjs.map +1 -0
  13. package/dist/execution/executor-manager.d.ts +51 -0
  14. package/dist/execution/executor-manager.js +149 -0
  15. package/dist/execution/executor-manager.js.map +1 -0
  16. package/dist/execution/queue-manager.cjs +43 -0
  17. package/dist/execution/queue-manager.cjs.map +1 -0
  18. package/dist/execution/queue-manager.d.ts +23 -0
  19. package/dist/execution/queue-manager.js +41 -0
  20. package/dist/execution/queue-manager.js.map +1 -0
  21. package/dist/index.cjs +38 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +16 -0
  24. package/dist/index.js +17 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/job/constants.cjs +30 -0
  27. package/dist/job/constants.cjs.map +1 -0
  28. package/dist/job/constants.d.ts +20 -0
  29. package/dist/job/constants.js +28 -0
  30. package/dist/job/constants.js.map +1 -0
  31. package/dist/job/job-builder.cjs +153 -0
  32. package/dist/job/job-builder.cjs.map +1 -0
  33. package/dist/job/job-builder.d.ts +115 -0
  34. package/dist/job/job-builder.js +151 -0
  35. package/dist/job/job-builder.js.map +1 -0
  36. package/dist/job/job-transitioner.cjs +36 -0
  37. package/dist/job/job-transitioner.cjs.map +1 -0
  38. package/dist/job/job-transitioner.d.ts +21 -0
  39. package/dist/job/job-transitioner.js +34 -0
  40. package/dist/job/job-transitioner.js.map +1 -0
  41. package/dist/job/job.cjs +250 -0
  42. package/dist/job/job.cjs.map +1 -0
  43. package/dist/job/job.d.ts +178 -0
  44. package/dist/job/job.js +248 -0
  45. package/dist/job/job.js.map +1 -0
  46. package/dist/queue/grant-queue-config.cjs +49 -0
  47. package/dist/queue/grant-queue-config.cjs.map +1 -0
  48. package/dist/queue/grant-queue-config.d.ts +32 -0
  49. package/dist/queue/grant-queue-config.js +46 -0
  50. package/dist/queue/grant-queue-config.js.map +1 -0
  51. package/dist/routines/cleanup-finished-job.cjs +17 -0
  52. package/dist/routines/cleanup-finished-job.cjs.map +1 -0
  53. package/dist/routines/cleanup-finished-job.d.ts +10 -0
  54. package/dist/routines/cleanup-finished-job.js +15 -0
  55. package/dist/routines/cleanup-finished-job.js.map +1 -0
  56. package/dist/routines/release-stale-jobs.cjs +28 -0
  57. package/dist/routines/release-stale-jobs.cjs.map +1 -0
  58. package/dist/routines/release-stale-jobs.d.ts +12 -0
  59. package/dist/routines/release-stale-jobs.js +26 -0
  60. package/dist/routines/release-stale-jobs.js.map +1 -0
  61. package/dist/shared-runner/runner-pool.cjs +46 -0
  62. package/dist/shared-runner/runner-pool.cjs.map +1 -0
  63. package/dist/shared-runner/runner-pool.d.ts +28 -0
  64. package/dist/shared-runner/runner-pool.js +44 -0
  65. package/dist/shared-runner/runner-pool.js.map +1 -0
  66. package/dist/shared-runner/runner.cjs +39 -0
  67. package/dist/shared-runner/runner.cjs.map +1 -0
  68. package/dist/shared-runner/runner.d.ts +10 -0
  69. package/dist/shared-runner/runner.js +35 -0
  70. package/dist/shared-runner/runner.js.map +1 -0
  71. package/dist/utils/shutdown.cjs +53 -0
  72. package/dist/utils/shutdown.cjs.map +1 -0
  73. package/dist/utils/shutdown.d.ts +9 -0
  74. package/dist/utils/shutdown.js +50 -0
  75. package/dist/utils/shutdown.js.map +1 -0
  76. package/dist/workers/main.cjs +153 -0
  77. package/dist/workers/main.cjs.map +1 -0
  78. package/dist/workers/main.d.ts +39 -0
  79. package/dist/workers/main.js +151 -0
  80. package/dist/workers/main.js.map +1 -0
  81. package/package.json +30 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job.js","sources":["../../src/job/job.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;MACmB,GAAG,CAAA;AACf,IAAA,cAAc;;AAGb,IAAA,EAAE;AACF,IAAA,MAAM;AACN,IAAA,KAAK;AACL,IAAA,KAAK;AACL,IAAA,KAAK;AACL,IAAA,IAAI;AACJ,IAAA,gBAAgB;AAChB,IAAA,OAAO;AACP,IAAA,YAAY;AACZ,IAAA,WAAW;AACX,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,MAAM;AACN,IAAA,MAAM;AACN,IAAA,YAAY;AACZ,IAAA,YAAY;AACZ,IAAA,SAAS;AACT,IAAA,WAAW;AACX,IAAA,UAAU;AACV,IAAA,UAAU;AACV,IAAA,aAAa;AACb,IAAA,iBAAiB;AAE1B;;AAEG;AACH,IAAA,WAAA,GAAA;AACE;;AAEG;AACH,QAAA,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;YACrE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC;YAC/B,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,MAAM,CAAA,CAAE,CAAC;AACrD,YAAA,OAAO,MAAM;AACf,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,aAAa,CAAC,OAAgB,EAAA;AAC5B,QAAA,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA,wBAAA,EAA2B,IAAI,CAAC,SAAS,CAAA,CAAA,CAAG,EAAE,OAAO,CAAC;AAC1E,QAAA,MA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AACN,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI;QACF,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI;;AAE9C,QAAA,MAAM,GAAG,GAA4B,MAAM,OAAO,SAAS,CAAC;AAE5D,QAAA,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,SAAS,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE;AAC9F,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,IAAI,SAAS,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;AAC3F,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,OAAO,KAAK;IACd;IAAE,OAAO,CAAC,EAAE;AACV,QAAA,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACjB,QAAA,OAAO,KAAK;IACd;AACF;;;;"}
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var core = require('@sidequest/core');
4
+
5
+ /**
6
+ * Determines if a new queue configuration differs from the existing queue configuration.
7
+ *
8
+ * Compares the provided queue data against the current queue configuration to detect
9
+ * any changes in concurrency, state, or priority properties. Only checks properties
10
+ * that are defined (truthy) in the new queue data.
11
+ *
12
+ * @param queue - The new queue data to compare against the existing configuration
13
+ * @param queueConfig - The current queue configuration to compare against
14
+ * @returns `true` if any of the defined properties in the new queue data differ from
15
+ * the corresponding properties in the existing configuration, `false` otherwise
16
+ */
17
+ function differentQueueConfig(queue, queueConfig) {
18
+ return ((!!queue.concurrency && queue.concurrency !== queueConfig.concurrency) ||
19
+ (!!queue.state && queue.state !== queueConfig.state) ||
20
+ (!!queue.priority && queue.priority !== queueConfig.priority));
21
+ }
22
+ /**
23
+ * Ensures a queue configuration exists, creating it if necessary.
24
+ * @param queue The name of the queue.
25
+ * @param config Optional configuration for the new queue.
26
+ * @returns The queue configuration.
27
+ */
28
+ async function grantQueueConfig(backend, queue, defaults) {
29
+ const queueConfig = await backend?.getQueue(queue.name);
30
+ if (queueConfig) {
31
+ if (differentQueueConfig(queue, queueConfig)) {
32
+ core.logger("Engine").warn(`Queue config for ${queue.name} exists but differs from the provided configuration. Updating...`);
33
+ return await backend.updateQueue({ ...queueConfig, ...queue });
34
+ }
35
+ else {
36
+ return queueConfig;
37
+ }
38
+ }
39
+ const newConfig = {
40
+ ...defaults,
41
+ ...queue,
42
+ };
43
+ core.logger("Engine").info(`Creating queue config for ${queue.name}`);
44
+ return backend?.createNewQueue(newConfig);
45
+ }
46
+
47
+ exports.differentQueueConfig = differentQueueConfig;
48
+ exports.grantQueueConfig = grantQueueConfig;
49
+ //# sourceMappingURL=grant-queue-config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant-queue-config.cjs","sources":["../../src/queue/grant-queue-config.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;AAUA;;;;;;;;;;;AAWG;AACG,SAAU,oBAAoB,CAAC,KAAmB,EAAE,WAAwB,EAAA;AAChF,IAAA,QACE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,WAAW,CAAC,WAAW;AACrE,SAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,WAAW,CAAC,KAAK,CAAC;AACpD,SAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,CAAC,QAAQ,CAAC;AAEjE;AAEA;;;;;AAKG;AACI,eAAe,gBAAgB,CAAC,OAAgB,EAAE,KAAmB,EAAE,QAAwB,EAAA;IACpG,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;IACvD,IAAI,WAAW,EAAE;AACf,QAAA,IAAI,oBAAoB,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE;AAC5C,YAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CACnB,CAAA,iBAAA,EAAoB,KAAK,CAAC,IAAI,CAAA,gEAAA,CAAkE,CACjG;AACD,YAAA,OAAO,MAAM,OAAO,CAAC,WAAW,CAAC,EAAE,GAAG,WAAW,EAAE,GAAG,KAAK,EAAE,CAAC;QAChE;aAAO;AACL,YAAA,OAAO,WAAW;QACpB;IACF;AAEA,IAAA,MAAM,SAAS,GAAiB;AAC9B,QAAA,GAAG,QAAQ;AACX,QAAA,GAAG,KAAK;KACT;AAED,IAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAA,0BAAA,EAA6B,KAAK,CAAC,IAAI,CAAA,CAAE,CAAC;AAEhE,IAAA,OAAO,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC;AAC3C;;;;;"}
@@ -0,0 +1,32 @@
1
+ import { NewQueueData, Backend } from '@sidequest/backend';
2
+ import { QueueConfig } from '@sidequest/core';
3
+
4
+ /**
5
+ * Represents the default configuration data for creating a new queue.
6
+ * This type excludes the 'id' field from NewQueueData, as IDs are typically
7
+ * generated automatically when creating new queue instances.
8
+ */
9
+ type QueueDefaults = Omit<NewQueueData, "id" | "name">;
10
+ /**
11
+ * Determines if a new queue configuration differs from the existing queue configuration.
12
+ *
13
+ * Compares the provided queue data against the current queue configuration to detect
14
+ * any changes in concurrency, state, or priority properties. Only checks properties
15
+ * that are defined (truthy) in the new queue data.
16
+ *
17
+ * @param queue - The new queue data to compare against the existing configuration
18
+ * @param queueConfig - The current queue configuration to compare against
19
+ * @returns `true` if any of the defined properties in the new queue data differ from
20
+ * the corresponding properties in the existing configuration, `false` otherwise
21
+ */
22
+ declare function differentQueueConfig(queue: NewQueueData, queueConfig: QueueConfig): boolean;
23
+ /**
24
+ * Ensures a queue configuration exists, creating it if necessary.
25
+ * @param queue The name of the queue.
26
+ * @param config Optional configuration for the new queue.
27
+ * @returns The queue configuration.
28
+ */
29
+ declare function grantQueueConfig(backend: Backend, queue: NewQueueData, defaults?: QueueDefaults): Promise<QueueConfig>;
30
+
31
+ export { differentQueueConfig, grantQueueConfig };
32
+ export type { QueueDefaults };
@@ -0,0 +1,46 @@
1
+ import { logger } from '@sidequest/core';
2
+
3
+ /**
4
+ * Determines if a new queue configuration differs from the existing queue configuration.
5
+ *
6
+ * Compares the provided queue data against the current queue configuration to detect
7
+ * any changes in concurrency, state, or priority properties. Only checks properties
8
+ * that are defined (truthy) in the new queue data.
9
+ *
10
+ * @param queue - The new queue data to compare against the existing configuration
11
+ * @param queueConfig - The current queue configuration to compare against
12
+ * @returns `true` if any of the defined properties in the new queue data differ from
13
+ * the corresponding properties in the existing configuration, `false` otherwise
14
+ */
15
+ function differentQueueConfig(queue, queueConfig) {
16
+ return ((!!queue.concurrency && queue.concurrency !== queueConfig.concurrency) ||
17
+ (!!queue.state && queue.state !== queueConfig.state) ||
18
+ (!!queue.priority && queue.priority !== queueConfig.priority));
19
+ }
20
+ /**
21
+ * Ensures a queue configuration exists, creating it if necessary.
22
+ * @param queue The name of the queue.
23
+ * @param config Optional configuration for the new queue.
24
+ * @returns The queue configuration.
25
+ */
26
+ async function grantQueueConfig(backend, queue, defaults) {
27
+ const queueConfig = await backend?.getQueue(queue.name);
28
+ if (queueConfig) {
29
+ if (differentQueueConfig(queue, queueConfig)) {
30
+ logger("Engine").warn(`Queue config for ${queue.name} exists but differs from the provided configuration. Updating...`);
31
+ return await backend.updateQueue({ ...queueConfig, ...queue });
32
+ }
33
+ else {
34
+ return queueConfig;
35
+ }
36
+ }
37
+ const newConfig = {
38
+ ...defaults,
39
+ ...queue,
40
+ };
41
+ logger("Engine").info(`Creating queue config for ${queue.name}`);
42
+ return backend?.createNewQueue(newConfig);
43
+ }
44
+
45
+ export { differentQueueConfig, grantQueueConfig };
46
+ //# sourceMappingURL=grant-queue-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant-queue-config.js","sources":["../../src/queue/grant-queue-config.ts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('@sidequest/core');
4
+
5
+ /**
6
+ * Deletes finished jobs older than one month from the backend.
7
+ * @param backend The backend instance to operate on.
8
+ * @param cutoffMs The cutoff time in milliseconds.
9
+ */
10
+ async function cleanupFinishedJobs(backend, cutoffMs) {
11
+ const cutoffDate = new Date(Date.now() - cutoffMs);
12
+ core.logger("Engine").debug(`Deleting finished jobs older than ${cutoffDate.toISOString()}`);
13
+ await backend?.deleteFinishedJobs(cutoffDate);
14
+ }
15
+
16
+ exports.cleanupFinishedJobs = cleanupFinishedJobs;
17
+ //# sourceMappingURL=cleanup-finished-job.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup-finished-job.cjs","sources":["../../src/routines/cleanup-finished-job.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;AAGA;;;;AAIG;AACI,eAAe,mBAAmB,CAAC,OAAgB,EAAE,QAAgB,EAAA;AAC1E,IAAA,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC;AAClD,IAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,UAAU,CAAC,WAAW,EAAE,CAAA,CAAE,CAAC;AACvF,IAAA,MAAM,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC;AAC/C;;;;"}
@@ -0,0 +1,10 @@
1
+ import { Backend } from '@sidequest/backend';
2
+
3
+ /**
4
+ * Deletes finished jobs older than one month from the backend.
5
+ * @param backend The backend instance to operate on.
6
+ * @param cutoffMs The cutoff time in milliseconds.
7
+ */
8
+ declare function cleanupFinishedJobs(backend: Backend, cutoffMs: number): Promise<void>;
9
+
10
+ export { cleanupFinishedJobs };
@@ -0,0 +1,15 @@
1
+ import { logger } from '@sidequest/core';
2
+
3
+ /**
4
+ * Deletes finished jobs older than one month from the backend.
5
+ * @param backend The backend instance to operate on.
6
+ * @param cutoffMs The cutoff time in milliseconds.
7
+ */
8
+ async function cleanupFinishedJobs(backend, cutoffMs) {
9
+ const cutoffDate = new Date(Date.now() - cutoffMs);
10
+ logger("Engine").debug(`Deleting finished jobs older than ${cutoffDate.toISOString()}`);
11
+ await backend?.deleteFinishedJobs(cutoffDate);
12
+ }
13
+
14
+ export { cleanupFinishedJobs };
15
+ //# sourceMappingURL=cleanup-finished-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup-finished-job.js","sources":["../../src/routines/cleanup-finished-job.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;AAIG;AACI,eAAe,mBAAmB,CAAC,OAAgB,EAAE,QAAgB,EAAA;AAC1E,IAAA,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC;AAClD,IAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,UAAU,CAAC,WAAW,EAAE,CAAA,CAAE,CAAC;AACvF,IAAA,MAAM,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC;AAC/C;;;;"}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var core = require('@sidequest/core');
4
+
5
+ /**
6
+ * Finds and releases stale jobs, making them available for processing again.
7
+ * @param backend The backend instance to operate on.
8
+ * @param maxStaleMs Maximum age of a job to be considered stale.
9
+ * @param maxClaimedMs Maximum age of a claimed job to be considered stale.
10
+ * @returns A promise that resolves when the operation is complete.
11
+ */
12
+ async function releaseStaleJobs(backend, maxStaleMs, maxClaimedMs) {
13
+ const staleJobs = await backend.staleJobs(maxStaleMs, maxClaimedMs);
14
+ if (staleJobs.length > 0) {
15
+ core.logger("Engine").info(`Stale jobs found, making them available to process`);
16
+ core.logger("Engine").debug(`Stale jobs: ${JSON.stringify(staleJobs)}`);
17
+ for (const jobData of staleJobs) {
18
+ jobData.state = "waiting";
19
+ await backend.updateJob(jobData);
20
+ }
21
+ }
22
+ else {
23
+ core.logger("Engine").debug(`No stale jobs found`);
24
+ }
25
+ }
26
+
27
+ exports.releaseStaleJobs = releaseStaleJobs;
28
+ //# sourceMappingURL=release-stale-jobs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-stale-jobs.cjs","sources":["../../src/routines/release-stale-jobs.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;AAGA;;;;;;AAMG;AACI,eAAe,gBAAgB,CAAC,OAAgB,EAAE,UAAkB,EAAE,YAAoB,EAAA;IAC/F,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;AAEnE,IAAA,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACxBA,WAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAA,kDAAA,CAAoD,CAAC;AAC3E,QAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,YAAA,EAAe,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA,CAAE,CAAC;AAClE,QAAA,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE;AAC/B,YAAA,OAAO,CAAC,KAAK,GAAG,SAAS;AACzB,YAAA,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;QAClC;IACF;SAAO;QACLA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,mBAAA,CAAqB,CAAC;IAC/C;AACF;;;;"}
@@ -0,0 +1,12 @@
1
+ import { Backend } from '@sidequest/backend';
2
+
3
+ /**
4
+ * Finds and releases stale jobs, making them available for processing again.
5
+ * @param backend The backend instance to operate on.
6
+ * @param maxStaleMs Maximum age of a job to be considered stale.
7
+ * @param maxClaimedMs Maximum age of a claimed job to be considered stale.
8
+ * @returns A promise that resolves when the operation is complete.
9
+ */
10
+ declare function releaseStaleJobs(backend: Backend, maxStaleMs: number, maxClaimedMs: number): Promise<void>;
11
+
12
+ export { releaseStaleJobs };
@@ -0,0 +1,26 @@
1
+ import { logger } from '@sidequest/core';
2
+
3
+ /**
4
+ * Finds and releases stale jobs, making them available for processing again.
5
+ * @param backend The backend instance to operate on.
6
+ * @param maxStaleMs Maximum age of a job to be considered stale.
7
+ * @param maxClaimedMs Maximum age of a claimed job to be considered stale.
8
+ * @returns A promise that resolves when the operation is complete.
9
+ */
10
+ async function releaseStaleJobs(backend, maxStaleMs, maxClaimedMs) {
11
+ const staleJobs = await backend.staleJobs(maxStaleMs, maxClaimedMs);
12
+ if (staleJobs.length > 0) {
13
+ logger("Engine").info(`Stale jobs found, making them available to process`);
14
+ logger("Engine").debug(`Stale jobs: ${JSON.stringify(staleJobs)}`);
15
+ for (const jobData of staleJobs) {
16
+ jobData.state = "waiting";
17
+ await backend.updateJob(jobData);
18
+ }
19
+ }
20
+ else {
21
+ logger("Engine").debug(`No stale jobs found`);
22
+ }
23
+ }
24
+
25
+ export { releaseStaleJobs };
26
+ //# sourceMappingURL=release-stale-jobs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-stale-jobs.js","sources":["../../src/routines/release-stale-jobs.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;AAMG;AACI,eAAe,gBAAgB,CAAC,OAAgB,EAAE,UAAkB,EAAE,YAAoB,EAAA;IAC/F,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;AAEnE,IAAA,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAA,kDAAA,CAAoD,CAAC;AAC3E,QAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,YAAA,EAAe,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA,CAAE,CAAC;AAClE,QAAA,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE;AAC/B,YAAA,OAAO,CAAC,KAAK,GAAG,SAAS;AACzB,YAAA,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;QAClC;IACF;SAAO;QACL,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,mBAAA,CAAqB,CAAC;IAC/C;AACF;;;;"}
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var core = require('@sidequest/core');
4
+ var path = require('path');
5
+ var Piscina = require('piscina');
6
+
7
+ const runnerPath = path.resolve(__dirname, "runner.js");
8
+ /**
9
+ * A pool of worker threads for running jobs in parallel using Piscina.
10
+ */
11
+ class RunnerPool {
12
+ /** The underlying Piscina worker pool. */
13
+ pool;
14
+ /**
15
+ * Creates a new RunnerPool.
16
+ * @param size The number of worker threads to use (defaults to number of CPUs).
17
+ */
18
+ constructor(minThreads, maxThreads) {
19
+ this.pool = new Piscina({
20
+ filename: runnerPath,
21
+ minThreads,
22
+ maxThreads,
23
+ });
24
+ core.logger("RunnerPool").debug(`Created worker pool with min ${minThreads} threads and max ${maxThreads} threads`);
25
+ }
26
+ /**
27
+ * Runs a job in the worker pool.
28
+ * @param job The job data to run.
29
+ * @param signal Optional event emitter for cancellation.
30
+ * @returns A promise resolving to the job result.
31
+ */
32
+ run(job, signal) {
33
+ core.logger("RunnerPool").debug(`Running job ${job.id} in pool`);
34
+ return this.pool.run(job, { signal });
35
+ }
36
+ /**
37
+ * Destroys the worker pool and releases resources.
38
+ */
39
+ async destroy() {
40
+ core.logger("RunnerPool").debug("Destroying worker pool");
41
+ await this.pool.destroy();
42
+ }
43
+ }
44
+
45
+ exports.RunnerPool = RunnerPool;
46
+ //# sourceMappingURL=runner-pool.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-pool.cjs","sources":["../../src/shared-runner/runner-pool.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;;;AAKA,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAmB,EAAE,WAAW,CAAC;AAEjE;;AAEG;MACU,UAAU,CAAA;;AAEJ,IAAA,IAAI;AAErB;;;AAGG;IACH,WAAA,CAAY,UAAkB,EAAE,UAAkB,EAAA;AAChD,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC;AACtB,YAAA,QAAQ,EAAE,UAAU;YACpB,UAAU;YACV,UAAU;AACX,SAAA,CAAC;AACF,QAAAA,WAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAA,6BAAA,EAAgC,UAAU,CAAA,iBAAA,EAAoB,UAAU,CAAA,QAAA,CAAU,CAAC;IAChH;AAEA;;;;;AAKG;IACH,GAAG,CAAC,GAAY,EAAE,MAAqB,EAAA;AACrC,QAAAA,WAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAA,YAAA,EAAe,GAAG,CAAC,EAAE,CAAA,QAAA,CAAU,CAAC;AAC3D,QAAA,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;IACvC;AAEA;;AAEG;AACH,IAAA,MAAM,OAAO,GAAA;QACXA,WAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC;AACpD,QAAA,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;IAC3B;AACD;;;;"}
@@ -0,0 +1,28 @@
1
+ import { JobData, JobResult } from '@sidequest/core';
2
+ import EventEmitter from 'events';
3
+
4
+ /**
5
+ * A pool of worker threads for running jobs in parallel using Piscina.
6
+ */
7
+ declare class RunnerPool {
8
+ /** The underlying Piscina worker pool. */
9
+ private readonly pool;
10
+ /**
11
+ * Creates a new RunnerPool.
12
+ * @param size The number of worker threads to use (defaults to number of CPUs).
13
+ */
14
+ constructor(minThreads: number, maxThreads: number);
15
+ /**
16
+ * Runs a job in the worker pool.
17
+ * @param job The job data to run.
18
+ * @param signal Optional event emitter for cancellation.
19
+ * @returns A promise resolving to the job result.
20
+ */
21
+ run(job: JobData, signal?: EventEmitter): Promise<JobResult>;
22
+ /**
23
+ * Destroys the worker pool and releases resources.
24
+ */
25
+ destroy(): Promise<void>;
26
+ }
27
+
28
+ export { RunnerPool };
@@ -0,0 +1,44 @@
1
+ import { logger } from '@sidequest/core';
2
+ import path from 'path';
3
+ import Piscina from 'piscina';
4
+
5
+ const runnerPath = path.resolve(import.meta.dirname, "runner.js");
6
+ /**
7
+ * A pool of worker threads for running jobs in parallel using Piscina.
8
+ */
9
+ class RunnerPool {
10
+ /** The underlying Piscina worker pool. */
11
+ pool;
12
+ /**
13
+ * Creates a new RunnerPool.
14
+ * @param size The number of worker threads to use (defaults to number of CPUs).
15
+ */
16
+ constructor(minThreads, maxThreads) {
17
+ this.pool = new Piscina({
18
+ filename: runnerPath,
19
+ minThreads,
20
+ maxThreads,
21
+ });
22
+ logger("RunnerPool").debug(`Created worker pool with min ${minThreads} threads and max ${maxThreads} threads`);
23
+ }
24
+ /**
25
+ * Runs a job in the worker pool.
26
+ * @param job The job data to run.
27
+ * @param signal Optional event emitter for cancellation.
28
+ * @returns A promise resolving to the job result.
29
+ */
30
+ run(job, signal) {
31
+ logger("RunnerPool").debug(`Running job ${job.id} in pool`);
32
+ return this.pool.run(job, { signal });
33
+ }
34
+ /**
35
+ * Destroys the worker pool and releases resources.
36
+ */
37
+ async destroy() {
38
+ logger("RunnerPool").debug("Destroying worker pool");
39
+ await this.pool.destroy();
40
+ }
41
+ }
42
+
43
+ export { RunnerPool };
44
+ //# sourceMappingURL=runner-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-pool.js","sources":["../../src/shared-runner/runner-pool.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;AAEjE;;AAEG;MACU,UAAU,CAAA;;AAEJ,IAAA,IAAI;AAErB;;;AAGG;IACH,WAAA,CAAY,UAAkB,EAAE,UAAkB,EAAA;AAChD,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC;AACtB,YAAA,QAAQ,EAAE,UAAU;YACpB,UAAU;YACV,UAAU;AACX,SAAA,CAAC;AACF,QAAA,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAA,6BAAA,EAAgC,UAAU,CAAA,iBAAA,EAAoB,UAAU,CAAA,QAAA,CAAU,CAAC;IAChH;AAEA;;;;;AAKG;IACH,GAAG,CAAC,GAAY,EAAE,MAAqB,EAAA;AACrC,QAAA,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAA,YAAA,EAAe,GAAG,CAAC,EAAE,CAAA,QAAA,CAAU,CAAC;AAC3D,QAAA,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC;IACvC;AAEA;;AAEG;AACH,IAAA,MAAM,OAAO,GAAA;QACX,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC;AACpD,QAAA,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;IAC3B;AACD;;;;"}
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@sidequest/core');
6
+
7
+ /**
8
+ * Runs a job by dynamically importing its script and executing the specified class.
9
+ * @param jobData The job data to execute.
10
+ * @returns A promise resolving to the job result.
11
+ */
12
+ async function run(jobData) {
13
+ let script = {};
14
+ try {
15
+ core.logger("Runner").debug(`Importing job script "${jobData.script}"`);
16
+ script = (await import(jobData.script));
17
+ core.logger("Runner").debug(`Successfully imported job script "${jobData.script}"`);
18
+ }
19
+ catch (error) {
20
+ const errorMessage = `Failed to import job script "${jobData.script}": ${error instanceof Error ? error.message : String(error)}`;
21
+ core.logger("Runner").error(errorMessage);
22
+ const errorData = core.toErrorData(error);
23
+ return { __is_job_transition__: true, type: "failed", error: errorData };
24
+ }
25
+ const JobClass = script[jobData.class] ?? script.default;
26
+ if (!JobClass || typeof JobClass !== "function") {
27
+ const error = `Invalid job class: ${jobData.class}`;
28
+ core.logger("Runner").error(error);
29
+ const errorData = core.toErrorData(new Error(error));
30
+ return { __is_job_transition__: true, type: "failed", error: errorData };
31
+ }
32
+ const job = new JobClass(jobData.constructor_args);
33
+ job.injectJobData(jobData);
34
+ core.logger("Runner").debug(`Executing job class "${jobData.class}" with args:`, jobData.args);
35
+ return job.perform(...jobData.args);
36
+ }
37
+
38
+ exports.default = run;
39
+ //# sourceMappingURL=runner.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.cjs","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":["logger","toErrorData"],"mappings":";;;;;;AAGA;;;;AAIG;AACY,eAAe,GAAG,CAAC,OAAgB,EAAA;IAChD,IAAI,MAAM,GAAiC,EAAE;AAC7C,IAAA,IAAI;AACF,QAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,OAAO,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;QAClE,MAAM,IAAI,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,CAAiC;AACvE,QAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,OAAO,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;IAChF;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,CAAA,6BAAA,EAAgC,OAAO,CAAC,MAAM,CAAA,GAAA,EAAM,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA,CAAE;QACjIA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;AACpC,QAAA,MAAM,SAAS,GAAGC,gBAAW,CAAC,KAAc,CAAC;AAC7C,QAAA,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1E;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO;IACxD,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAC/C,QAAA,MAAM,KAAK,GAAG,CAAA,mBAAA,EAAsB,OAAO,CAAC,KAAK,EAAE;QACnDD,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;QAC7B,MAAM,SAAS,GAAGC,gBAAW,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC/C,QAAA,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1E;IACA,MAAM,GAAG,GAAQ,IAAI,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC;AACvD,IAAA,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC;AAC1B,IAAAD,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,OAAO,CAAC,KAAK,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC;IACzF,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;AACrC;;;;"}
@@ -0,0 +1,10 @@
1
+ import { JobData, JobResult } from '@sidequest/core';
2
+
3
+ /**
4
+ * Runs a job by dynamically importing its script and executing the specified class.
5
+ * @param jobData The job data to execute.
6
+ * @returns A promise resolving to the job result.
7
+ */
8
+ declare function run(jobData: JobData): Promise<JobResult>;
9
+
10
+ export { run as default };
@@ -0,0 +1,35 @@
1
+ import { logger, toErrorData } from '@sidequest/core';
2
+
3
+ /**
4
+ * Runs a job by dynamically importing its script and executing the specified class.
5
+ * @param jobData The job data to execute.
6
+ * @returns A promise resolving to the job result.
7
+ */
8
+ async function run(jobData) {
9
+ let script = {};
10
+ try {
11
+ logger("Runner").debug(`Importing job script "${jobData.script}"`);
12
+ script = (await import(jobData.script));
13
+ logger("Runner").debug(`Successfully imported job script "${jobData.script}"`);
14
+ }
15
+ catch (error) {
16
+ const errorMessage = `Failed to import job script "${jobData.script}": ${error instanceof Error ? error.message : String(error)}`;
17
+ logger("Runner").error(errorMessage);
18
+ const errorData = toErrorData(error);
19
+ return { __is_job_transition__: true, type: "failed", error: errorData };
20
+ }
21
+ const JobClass = script[jobData.class] ?? script.default;
22
+ if (!JobClass || typeof JobClass !== "function") {
23
+ const error = `Invalid job class: ${jobData.class}`;
24
+ logger("Runner").error(error);
25
+ const errorData = toErrorData(new Error(error));
26
+ return { __is_job_transition__: true, type: "failed", error: errorData };
27
+ }
28
+ const job = new JobClass(jobData.constructor_args);
29
+ job.injectJobData(jobData);
30
+ logger("Runner").debug(`Executing job class "${jobData.class}" with args:`, jobData.args);
31
+ return job.perform(...jobData.args);
32
+ }
33
+
34
+ export { run as default };
35
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;AAIG;AACY,eAAe,GAAG,CAAC,OAAgB,EAAA;IAChD,IAAI,MAAM,GAAiC,EAAE;AAC7C,IAAA,IAAI;AACF,QAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,OAAO,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;QAClE,MAAM,IAAI,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,CAAiC;AACvE,QAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,OAAO,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;IAChF;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,CAAA,6BAAA,EAAgC,OAAO,CAAC,MAAM,CAAA,GAAA,EAAM,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA,CAAE;QACjI,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;AACpC,QAAA,MAAM,SAAS,GAAG,WAAW,CAAC,KAAc,CAAC;AAC7C,QAAA,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1E;AAEA,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO;IACxD,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAC/C,QAAA,MAAM,KAAK,GAAG,CAAA,mBAAA,EAAsB,OAAO,CAAC,KAAK,EAAE;QACnD,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;QAC7B,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC/C,QAAA,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1E;IACA,MAAM,GAAG,GAAQ,IAAI,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC;AACvD,IAAA,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC;AAC1B,IAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,OAAO,CAAC,KAAK,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC;IACzF,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;AACrC;;;;"}
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var core = require('@sidequest/core');
4
+
5
+ let shuttingDown = false;
6
+ /**
7
+ * Handles the shutdown process, ensuring it only runs once and logs appropriately.
8
+ * @param fn The async function to run during shutdown.
9
+ * @param tag A label for logging.
10
+ * @param signal The signal that triggered shutdown.
11
+ */
12
+ async function shutdown(fn, tag, signal) {
13
+ try {
14
+ if (!shuttingDown) {
15
+ shuttingDown = true;
16
+ core.logger("Engine").info(`[${tag}] Received ${signal}. Shutting down gracefully...`);
17
+ await fn();
18
+ }
19
+ else {
20
+ core.logger("Engine").info(`[${tag}] Received ${signal} while already shutting down. Forcing shutdown.`);
21
+ }
22
+ core.logger("Engine").info(`[${tag}] Shutdown complete.`);
23
+ process.exit(0);
24
+ }
25
+ catch (error) {
26
+ core.logger("Engine").error(`[${tag}] Error during shutdown:`, error);
27
+ process.exit(1);
28
+ }
29
+ }
30
+ /* eslint-disable @typescript-eslint/no-misused-promises */
31
+ /**
32
+ * Registers handlers for SIGINT and SIGTERM to gracefully shut down the process.
33
+ * @param fn The async function to run during shutdown.
34
+ * @param tag A label for logging.
35
+ */
36
+ function gracefulShutdown(fn, tag, enabled) {
37
+ if (enabled) {
38
+ process.on("SIGINT", async () => {
39
+ await shutdown(fn, tag, "SIGINT");
40
+ });
41
+ process.on("SIGTERM", async () => {
42
+ await shutdown(fn, tag, "SIGTERM");
43
+ });
44
+ }
45
+ }
46
+ function clearGracefulShutdown() {
47
+ process.removeAllListeners("SIGINT");
48
+ process.removeAllListeners("SIGTERM");
49
+ }
50
+
51
+ exports.clearGracefulShutdown = clearGracefulShutdown;
52
+ exports.gracefulShutdown = gracefulShutdown;
53
+ //# sourceMappingURL=shutdown.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.cjs","sources":["../../src/utils/shutdown.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;AAEA,IAAI,YAAY,GAAG,KAAK;AAExB;;;;;AAKG;AACH,eAAe,QAAQ,CAAC,EAA8B,EAAE,GAAW,EAAE,MAAc,EAAA;AACjF,IAAA,IAAI;QACF,IAAI,CAAC,YAAY,EAAE;YACjB,YAAY,GAAG,IAAI;AACnB,YAAAA,WAAM,CAAC,QAAQ,CA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+ * @param fn The async function to run during shutdown.
4
+ * @param tag A label for logging.
5
+ */
6
+ declare function gracefulShutdown(fn: () => void | Promise<void>, tag: string, enabled: boolean): void;
7
+ declare function clearGracefulShutdown(): void;
8
+
9
+ export { clearGracefulShutdown, gracefulShutdown };
@@ -0,0 +1,50 @@
1
+ import { logger } from '@sidequest/core';
2
+
3
+ let shuttingDown = false;
4
+ /**
5
+ * Handles the shutdown process, ensuring it only runs once and logs appropriately.
6
+ * @param fn The async function to run during shutdown.
7
+ * @param tag A label for logging.
8
+ * @param signal The signal that triggered shutdown.
9
+ */
10
+ async function shutdown(fn, tag, signal) {
11
+ try {
12
+ if (!shuttingDown) {
13
+ shuttingDown = true;
14
+ logger("Engine").info(`[${tag}] Received ${signal}. Shutting down gracefully...`);
15
+ await fn();
16
+ }
17
+ else {
18
+ logger("Engine").info(`[${tag}] Received ${signal} while already shutting down. Forcing shutdown.`);
19
+ }
20
+ logger("Engine").info(`[${tag}] Shutdown complete.`);
21
+ process.exit(0);
22
+ }
23
+ catch (error) {
24
+ logger("Engine").error(`[${tag}] Error during shutdown:`, error);
25
+ process.exit(1);
26
+ }
27
+ }
28
+ /* eslint-disable @typescript-eslint/no-misused-promises */
29
+ /**
30
+ * Registers handlers for SIGINT and SIGTERM to gracefully shut down the process.
31
+ * @param fn The async function to run during shutdown.
32
+ * @param tag A label for logging.
33
+ */
34
+ function gracefulShutdown(fn, tag, enabled) {
35
+ if (enabled) {
36
+ process.on("SIGINT", async () => {
37
+ await shutdown(fn, tag, "SIGINT");
38
+ });
39
+ process.on("SIGTERM", async () => {
40
+ await shutdown(fn, tag, "SIGTERM");
41
+ });
42
+ }
43
+ }
44
+ function clearGracefulShutdown() {
45
+ process.removeAllListeners("SIGINT");
46
+ process.removeAllListeners("SIGTERM");
47
+ }
48
+
49
+ export { clearGracefulShutdown, gracefulShutdown };
50
+ //# sourceMappingURL=shutdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.js","sources":["../../src/utils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