@donkeylabs/server 0.4.7 → 0.4.8
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/docs/external-jobs.md +420 -0
- package/docs/workflows.md +509 -0
- package/package.json +1 -1
- package/src/core/external-job-socket.ts +356 -0
- package/src/core/external-jobs.ts +237 -0
- package/src/core/index.ts +49 -0
- package/src/core/jobs.ts +652 -9
- package/src/core/workflows.ts +1173 -0
- package/src/core.ts +2 -0
- package/src/harness.ts +3 -0
- package/src/server.ts +15 -2
package/src/core.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { Jobs } from "./core/jobs";
|
|
|
10
10
|
import type { SSE } from "./core/sse";
|
|
11
11
|
import type { RateLimiter } from "./core/rate-limiter";
|
|
12
12
|
import type { Errors, CustomErrorRegistry } from "./core/errors";
|
|
13
|
+
import type { Workflows } from "./core/workflows";
|
|
13
14
|
|
|
14
15
|
export interface PluginRegistry {}
|
|
15
16
|
|
|
@@ -52,6 +53,7 @@ export interface CoreServices {
|
|
|
52
53
|
sse: SSE;
|
|
53
54
|
rateLimiter: RateLimiter;
|
|
54
55
|
errors: Errors;
|
|
56
|
+
workflows: Workflows;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
package/src/harness.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createSSE,
|
|
12
12
|
createRateLimiter,
|
|
13
13
|
createErrors,
|
|
14
|
+
createWorkflows,
|
|
14
15
|
} from "./core/index";
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -34,6 +35,7 @@ export async function createTestHarness(targetPlugin: Plugin, dependencies: Plug
|
|
|
34
35
|
const sse = createSSE();
|
|
35
36
|
const rateLimiter = createRateLimiter();
|
|
36
37
|
const errors = createErrors();
|
|
38
|
+
const workflows = createWorkflows({ events, jobs, sse });
|
|
37
39
|
|
|
38
40
|
const core: CoreServices = {
|
|
39
41
|
db,
|
|
@@ -46,6 +48,7 @@ export async function createTestHarness(targetPlugin: Plugin, dependencies: Plug
|
|
|
46
48
|
sse,
|
|
47
49
|
rateLimiter,
|
|
48
50
|
errors,
|
|
51
|
+
workflows,
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
const manager = new PluginManager(core);
|
package/src/server.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
createSSE,
|
|
15
15
|
createRateLimiter,
|
|
16
16
|
createErrors,
|
|
17
|
+
createWorkflows,
|
|
17
18
|
extractClientIP,
|
|
18
19
|
HttpError,
|
|
19
20
|
type LoggerConfig,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
type SSEConfig,
|
|
25
26
|
type RateLimiterConfig,
|
|
26
27
|
type ErrorsConfig,
|
|
28
|
+
type WorkflowsConfig,
|
|
27
29
|
} from "./core/index";
|
|
28
30
|
import { zodSchemaToTs } from "./generator/zod-to-ts";
|
|
29
31
|
|
|
@@ -57,6 +59,7 @@ export interface ServerConfig {
|
|
|
57
59
|
sse?: SSEConfig;
|
|
58
60
|
rateLimiter?: RateLimiterConfig;
|
|
59
61
|
errors?: ErrorsConfig;
|
|
62
|
+
workflows?: WorkflowsConfig;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
export class AppServer {
|
|
@@ -79,6 +82,12 @@ export class AppServer {
|
|
|
79
82
|
const sse = createSSE(options.sse);
|
|
80
83
|
const rateLimiter = createRateLimiter(options.rateLimiter);
|
|
81
84
|
const errors = createErrors(options.errors);
|
|
85
|
+
const workflows = createWorkflows({
|
|
86
|
+
...options.workflows,
|
|
87
|
+
events,
|
|
88
|
+
jobs,
|
|
89
|
+
sse,
|
|
90
|
+
});
|
|
82
91
|
|
|
83
92
|
this.coreServices = {
|
|
84
93
|
db: options.db,
|
|
@@ -91,6 +100,7 @@ export class AppServer {
|
|
|
91
100
|
sse,
|
|
92
101
|
rateLimiter,
|
|
93
102
|
errors,
|
|
103
|
+
workflows,
|
|
94
104
|
};
|
|
95
105
|
|
|
96
106
|
this.manager = new PluginManager(this.coreServices);
|
|
@@ -447,7 +457,8 @@ ${factoryFunction}
|
|
|
447
457
|
|
|
448
458
|
this.coreServices.cron.start();
|
|
449
459
|
this.coreServices.jobs.start();
|
|
450
|
-
|
|
460
|
+
await this.coreServices.workflows.resume();
|
|
461
|
+
logger.info("Background services started (cron, jobs, workflows)");
|
|
451
462
|
|
|
452
463
|
for (const router of this.routers) {
|
|
453
464
|
for (const route of router.getRoutes()) {
|
|
@@ -665,7 +676,8 @@ ${factoryFunction}
|
|
|
665
676
|
// 3. Start background services
|
|
666
677
|
this.coreServices.cron.start();
|
|
667
678
|
this.coreServices.jobs.start();
|
|
668
|
-
|
|
679
|
+
await this.coreServices.workflows.resume();
|
|
680
|
+
logger.info("Background services started (cron, jobs, workflows)");
|
|
669
681
|
|
|
670
682
|
// 4. Build route map
|
|
671
683
|
for (const router of this.routers) {
|
|
@@ -805,6 +817,7 @@ ${factoryFunction}
|
|
|
805
817
|
this.coreServices.sse.shutdown();
|
|
806
818
|
|
|
807
819
|
// Stop background services
|
|
820
|
+
await this.coreServices.workflows.stop();
|
|
808
821
|
await this.coreServices.jobs.stop();
|
|
809
822
|
await this.coreServices.cron.stop();
|
|
810
823
|
|