@powerhousedao/reactor 4.1.0-dev.7 → 4.1.0-dev.70
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/dist/src/client/reactor-client.d.ts +103 -0
- package/dist/src/client/reactor-client.d.ts.map +1 -0
- package/dist/src/client/reactor-client.js +184 -0
- package/dist/src/client/reactor-client.js.map +1 -0
- package/dist/src/client/types.d.ts +213 -0
- package/dist/src/client/types.d.ts.map +1 -0
- package/dist/src/client/types.js +14 -0
- package/dist/src/client/types.js.map +1 -0
- package/dist/src/core/builder.d.ts +20 -0
- package/dist/src/core/builder.d.ts.map +1 -0
- package/dist/src/core/builder.js +47 -0
- package/dist/src/core/builder.js.map +1 -0
- package/dist/src/core/reactor.d.ts +98 -0
- package/dist/src/core/reactor.d.ts.map +1 -0
- package/dist/src/core/reactor.js +630 -0
- package/dist/src/core/reactor.js.map +1 -0
- package/dist/src/core/types.d.ts +121 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/utils.d.ts +11 -0
- package/dist/src/core/utils.d.ts.map +1 -0
- package/dist/src/core/utils.js +31 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/events/event-bus.d.ts +3 -3
- package/dist/src/events/event-bus.d.ts.map +1 -1
- package/dist/src/events/event-bus.js.map +1 -1
- package/dist/src/events/interfaces.d.ts +1 -1
- package/dist/src/events/interfaces.d.ts.map +1 -1
- package/dist/src/events/types.d.ts +1 -1
- package/dist/src/events/types.d.ts.map +1 -1
- package/dist/src/events/types.js.map +1 -1
- package/dist/src/executor/interfaces.d.ts +31 -54
- package/dist/src/executor/interfaces.d.ts.map +1 -1
- package/dist/src/executor/simple-job-executor-manager.d.ts +27 -0
- package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -0
- package/dist/src/executor/simple-job-executor-manager.js +128 -0
- package/dist/src/executor/simple-job-executor-manager.js.map +1 -0
- package/dist/src/executor/simple-job-executor.d.ts +29 -0
- package/dist/src/executor/simple-job-executor.d.ts.map +1 -0
- package/dist/src/executor/simple-job-executor.js +154 -0
- package/dist/src/executor/simple-job-executor.js.map +1 -0
- package/dist/src/executor/types.d.ts +23 -8
- package/dist/src/executor/types.d.ts.map +1 -1
- package/dist/src/executor/types.js.map +1 -1
- package/dist/src/index.d.ts +19 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +25 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/queue/interfaces.d.ts +45 -5
- package/dist/src/queue/interfaces.d.ts.map +1 -1
- package/dist/src/queue/job-execution-handle.d.ts +24 -0
- package/dist/src/queue/job-execution-handle.d.ts.map +1 -0
- package/dist/src/queue/job-execution-handle.js +62 -0
- package/dist/src/queue/job-execution-handle.js.map +1 -0
- package/dist/src/queue/queue.d.ts +54 -5
- package/dist/src/queue/queue.d.ts.map +1 -1
- package/dist/src/queue/queue.js +265 -36
- package/dist/src/queue/queue.js.map +1 -1
- package/dist/src/queue/types.d.ts +26 -1
- package/dist/src/queue/types.d.ts.map +1 -1
- package/dist/src/queue/types.js +12 -0
- package/dist/src/queue/types.js.map +1 -1
- package/dist/src/read-models/document-view.d.ts +21 -0
- package/dist/src/read-models/document-view.d.ts.map +1 -0
- package/dist/src/read-models/document-view.js +285 -0
- package/dist/src/read-models/document-view.js.map +1 -0
- package/dist/src/read-models/types.d.ts +46 -0
- package/dist/src/read-models/types.d.ts.map +1 -0
- package/dist/src/read-models/types.js +2 -0
- package/dist/src/read-models/types.js.map +1 -0
- package/dist/src/registry/implementation.d.ts +62 -0
- package/dist/src/registry/implementation.d.ts.map +1 -0
- package/dist/src/registry/implementation.js +96 -0
- package/dist/src/registry/implementation.js.map +1 -0
- package/dist/src/registry/index.d.ts +3 -0
- package/dist/src/registry/index.d.ts.map +1 -0
- package/dist/src/registry/index.js +2 -0
- package/dist/src/registry/index.js.map +1 -0
- package/dist/src/registry/interfaces.d.ts +39 -0
- package/dist/src/registry/interfaces.d.ts.map +1 -0
- package/dist/src/registry/interfaces.js +2 -0
- package/dist/src/registry/interfaces.js.map +1 -0
- package/dist/src/shared/awaiter.d.ts +32 -0
- package/dist/src/shared/awaiter.d.ts.map +1 -0
- package/dist/src/shared/awaiter.js +132 -0
- package/dist/src/shared/awaiter.js.map +1 -0
- package/dist/src/shared/errors.d.ts +9 -0
- package/dist/src/shared/errors.d.ts.map +1 -0
- package/dist/src/shared/errors.js +18 -0
- package/dist/src/shared/errors.js.map +1 -0
- package/dist/src/shared/factories.d.ts +16 -0
- package/dist/src/shared/factories.d.ts.map +1 -0
- package/dist/src/shared/factories.js +33 -0
- package/dist/src/shared/factories.js.map +1 -0
- package/dist/src/shared/types.d.ts +91 -19
- package/dist/src/shared/types.d.ts.map +1 -1
- package/dist/src/shared/types.js +35 -1
- package/dist/src/shared/types.js.map +1 -1
- package/dist/src/shared/utils.d.ts +3 -0
- package/dist/src/shared/utils.d.ts.map +1 -0
- package/dist/src/shared/utils.js +8 -0
- package/dist/src/shared/utils.js.map +1 -0
- package/dist/src/signer/passthrough-signer.d.ts +6 -0
- package/dist/src/signer/passthrough-signer.d.ts.map +1 -0
- package/dist/src/signer/passthrough-signer.js +6 -0
- package/dist/src/signer/passthrough-signer.js.map +1 -0
- package/dist/src/signer/types.d.ts +15 -0
- package/dist/src/signer/types.d.ts.map +1 -0
- package/dist/src/signer/types.js +2 -0
- package/dist/src/signer/types.js.map +1 -0
- package/dist/src/storage/interfaces.d.ts +125 -0
- package/dist/src/storage/interfaces.d.ts.map +1 -0
- package/dist/src/storage/interfaces.js +19 -0
- package/dist/src/storage/interfaces.js.map +1 -0
- package/dist/src/storage/kysely/store.d.ts +15 -0
- package/dist/src/storage/kysely/store.d.ts.map +1 -0
- package/dist/src/storage/kysely/store.js +173 -0
- package/dist/src/storage/kysely/store.js.map +1 -0
- package/dist/src/storage/kysely/types.d.ts +26 -0
- package/dist/src/storage/kysely/types.d.ts.map +1 -0
- package/dist/src/storage/kysely/types.js +2 -0
- package/dist/src/storage/kysely/types.js.map +1 -0
- package/dist/src/storage/txn.d.ts +15 -0
- package/dist/src/storage/txn.d.ts.map +1 -0
- package/dist/src/storage/txn.js +42 -0
- package/dist/src/storage/txn.js.map +1 -0
- package/dist/src/subs/default-error-handler.d.ts +13 -0
- package/dist/src/subs/default-error-handler.d.ts.map +1 -0
- package/dist/src/subs/default-error-handler.js +27 -0
- package/dist/src/subs/default-error-handler.js.map +1 -0
- package/dist/src/subs/react-subscription-manager.d.ts +45 -0
- package/dist/src/subs/react-subscription-manager.d.ts.map +1 -0
- package/dist/src/subs/react-subscription-manager.js +185 -0
- package/dist/src/subs/react-subscription-manager.js.map +1 -0
- package/dist/src/subs/types.d.ts +64 -0
- package/dist/src/subs/types.d.ts.map +1 -0
- package/dist/src/subs/types.js +2 -0
- package/dist/src/subs/types.js.map +1 -0
- package/package.json +13 -5
- package/dist/bench/end-to-end-flow.bench.d.ts +0 -2
- package/dist/bench/end-to-end-flow.bench.d.ts.map +0 -1
- package/dist/bench/end-to-end-flow.bench.js +0 -256
- package/dist/bench/end-to-end-flow.bench.js.map +0 -1
- package/dist/bench/event-bus.bench.d.ts +0 -2
- package/dist/bench/event-bus.bench.d.ts.map +0 -1
- package/dist/bench/event-bus.bench.js +0 -238
- package/dist/bench/event-bus.bench.js.map +0 -1
- package/dist/bench/queue-only.bench.d.ts +0 -2
- package/dist/bench/queue-only.bench.d.ts.map +0 -1
- package/dist/bench/queue-only.bench.js +0 -40
- package/dist/bench/queue-only.bench.js.map +0 -1
- package/dist/bench/reactor-throughput.bench.d.ts +0 -2
- package/dist/bench/reactor-throughput.bench.d.ts.map +0 -1
- package/dist/bench/reactor-throughput.bench.js +0 -137
- package/dist/bench/reactor-throughput.bench.js.map +0 -1
- package/dist/src/executor/job-executor.d.ts +0 -62
- package/dist/src/executor/job-executor.d.ts.map +0 -1
- package/dist/src/executor/job-executor.js +0 -325
- package/dist/src/executor/job-executor.js.map +0 -1
- package/dist/test/event-bus.test.d.ts +0 -2
- package/dist/test/event-bus.test.d.ts.map +0 -1
- package/dist/test/event-bus.test.js +0 -532
- package/dist/test/event-bus.test.js.map +0 -1
- package/dist/test/job-executor.test.d.ts +0 -2
- package/dist/test/job-executor.test.d.ts.map +0 -1
- package/dist/test/job-executor.test.js +0 -581
- package/dist/test/job-executor.test.js.map +0 -1
- package/dist/test/queue.test.d.ts +0 -2
- package/dist/test/queue.test.d.ts.map +0 -1
- package/dist/test/queue.test.js +0 -396
- package/dist/test/queue.test.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Action, DocumentModelModule, Operation, PHDocument } from "document-model";
|
|
2
|
+
import type { JobInfo, PagedResults, PagingOptions, PropagationMode, SearchFilter, ShutdownStatus, ViewFilter } from "../shared/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The main Reactor interface that serves as a facade for document operations.
|
|
5
|
+
* This interface provides a unified API for document management, including
|
|
6
|
+
* creation, retrieval, mutation, and deletion operations.
|
|
7
|
+
*
|
|
8
|
+
* Phase 2 of the refactoring plan: IReactor Facade (Strangler Fig Pattern)
|
|
9
|
+
*/
|
|
10
|
+
export interface IReactor {
|
|
11
|
+
/**
|
|
12
|
+
* Signals that the reactor should shutdown.
|
|
13
|
+
*/
|
|
14
|
+
kill(): ShutdownStatus;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a list of document model modules.
|
|
17
|
+
*
|
|
18
|
+
* @param namespace - Optional namespace like "powerhouse" or "sky", defaults to ""
|
|
19
|
+
* @param paging - Optional options for paging data in large queries.
|
|
20
|
+
* @param signal - Optional abort signal to cancel the request
|
|
21
|
+
* @returns List of document model modules
|
|
22
|
+
*/
|
|
23
|
+
getDocumentModels(namespace?: string, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<DocumentModelModule>>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves a specific PHDocument by id
|
|
26
|
+
*
|
|
27
|
+
* @param id - Required, this is the document id
|
|
28
|
+
* @param view - Optional filter containing branch and scopes information
|
|
29
|
+
* @param signal - Optional abort signal to cancel the request
|
|
30
|
+
* @returns The up-to-date PHDocument with scopes and list of child document ids
|
|
31
|
+
*/
|
|
32
|
+
get<TDocument extends PHDocument>(id: string, view?: ViewFilter, signal?: AbortSignal): Promise<{
|
|
33
|
+
document: TDocument;
|
|
34
|
+
childIds: string[];
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves a specific PHDocument by slug
|
|
38
|
+
*
|
|
39
|
+
* @param slug - Required, this is the document slug
|
|
40
|
+
* @param view - Optional filter containing branch and scopes information
|
|
41
|
+
* @param signal - Optional abort signal to cancel the request
|
|
42
|
+
* @returns The up-to-date PHDocument with scopes and list of child document ids
|
|
43
|
+
*/
|
|
44
|
+
getBySlug<TDocument extends PHDocument>(slug: string, view?: ViewFilter, signal?: AbortSignal): Promise<{
|
|
45
|
+
document: TDocument;
|
|
46
|
+
childIds: string[];
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves the operations for a document
|
|
50
|
+
*
|
|
51
|
+
* @param documentId - The document id
|
|
52
|
+
* @param view - Optional filter containing branch and scopes information
|
|
53
|
+
* @param paging - Optional pagination options
|
|
54
|
+
* @param signal - Optional abort signal to cancel the request
|
|
55
|
+
* @returns The list of operations
|
|
56
|
+
*/
|
|
57
|
+
getOperations(documentId: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<Record<string, PagedResults<Operation>>>;
|
|
58
|
+
/**
|
|
59
|
+
* Filters documents by criteria and returns a list of them
|
|
60
|
+
*
|
|
61
|
+
* @param search - Search filter options (type, parentId, identifiers)
|
|
62
|
+
* @param view - Optional filter containing branch and scopes information
|
|
63
|
+
* @param paging - Optional pagination options
|
|
64
|
+
* @param signal - Optional abort signal to cancel the request
|
|
65
|
+
* @returns List of documents matching criteria and pagination cursor
|
|
66
|
+
*/
|
|
67
|
+
find(search: SearchFilter, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<PHDocument>>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a document
|
|
70
|
+
*
|
|
71
|
+
* @param document - Document with optional id, slug, parent, model type, and initial state
|
|
72
|
+
* @param signal - Optional abort signal to cancel the request
|
|
73
|
+
* @returns The job status
|
|
74
|
+
*/
|
|
75
|
+
create(document: PHDocument, signal?: AbortSignal): Promise<JobInfo>;
|
|
76
|
+
/**
|
|
77
|
+
* Deletes a document
|
|
78
|
+
*
|
|
79
|
+
* @param id - Document id
|
|
80
|
+
* @param propagate - Optional mode for handling children, CASCADE deletes child documents
|
|
81
|
+
* @param signal - Optional abort signal to cancel the request
|
|
82
|
+
* @returns The job id and status
|
|
83
|
+
*/
|
|
84
|
+
deleteDocument(id: string, propagate?: PropagationMode, signal?: AbortSignal): Promise<JobInfo>;
|
|
85
|
+
/**
|
|
86
|
+
* Applies a list of actions to a document.
|
|
87
|
+
*
|
|
88
|
+
* @param id - Document id
|
|
89
|
+
* @param actions - List of actions to apply
|
|
90
|
+
* @returns The job id and status
|
|
91
|
+
*/
|
|
92
|
+
mutate(id: string, actions: Action[]): Promise<JobInfo>;
|
|
93
|
+
/**
|
|
94
|
+
* Adds multiple documents as children to another
|
|
95
|
+
*
|
|
96
|
+
* @param parentId - Parent document id
|
|
97
|
+
* @param documentIds - List of document ids to add as children
|
|
98
|
+
* @param view - Optional filter containing branch and scopes information
|
|
99
|
+
* @param signal - Optional abort signal to cancel the request
|
|
100
|
+
* @returns The job id and status
|
|
101
|
+
*/
|
|
102
|
+
addChildren(parentId: string, documentIds: string[], view?: ViewFilter, signal?: AbortSignal): Promise<JobInfo>;
|
|
103
|
+
/**
|
|
104
|
+
* Removes multiple documents as children from another
|
|
105
|
+
*
|
|
106
|
+
* @param parentId - Parent document id
|
|
107
|
+
* @param documentIds - List of document ids to remove as children
|
|
108
|
+
* @param view - Optional filter containing branch and scopes information
|
|
109
|
+
* @param signal - Optional abort signal to cancel the request
|
|
110
|
+
* @returns The job id and status
|
|
111
|
+
*/
|
|
112
|
+
removeChildren(parentId: string, documentIds: string[], view?: ViewFilter, signal?: AbortSignal): Promise<JobInfo>;
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves the status of a job
|
|
115
|
+
*
|
|
116
|
+
* @param jobId - The job id
|
|
117
|
+
* @returns The job status
|
|
118
|
+
*/
|
|
119
|
+
getJobStatus(jobId: string, signal?: AbortSignal): Promise<JobInfo>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,SAAS,EACT,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,UAAU,EACX,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,IAAI,cAAc,CAAC;IAEvB;;;;;;;OAOG;IACH,iBAAiB,CACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE9C;;;;;;;OAOG;IACH,GAAG,CAAC,SAAS,SAAS,UAAU,EAC9B,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QACT,QAAQ,EAAE,SAAS,CAAC;QACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC,CAAC;IAEH;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,S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CACZ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EAAE,EACrB,IAAI,CAAC,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PHDocument } from "document-model";
|
|
2
|
+
import type { PagedResults } from "../shared/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Filters paged results by parent ID
|
|
5
|
+
*/
|
|
6
|
+
export declare function filterByParentId(results: PagedResults<PHDocument>, parentId: string): PagedResults<PHDocument>;
|
|
7
|
+
/**
|
|
8
|
+
* Filters paged results by document type
|
|
9
|
+
*/
|
|
10
|
+
export declare function filterByType(results: PagedResults<PHDocument>, type: string): PagedResults<PHDocument>;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,EAEjC,QAAQ,EAAE,MAAM,GACf,YAAY,CAAC,UAAU,CAAC,CAG1B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,EACjC,IAAI,EAAE,MAAM,GACX,YAAY,CAAC,UAAU,CAAC,CAoB1B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters paged results by parent ID
|
|
3
|
+
*/
|
|
4
|
+
export function filterByParentId(results,
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
parentId) {
|
|
7
|
+
// TODO: Implement filterByParentId
|
|
8
|
+
return results;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Filters paged results by document type
|
|
12
|
+
*/
|
|
13
|
+
export function filterByType(results, type) {
|
|
14
|
+
// Filter documents by their document type from the header
|
|
15
|
+
const filteredDocuments = results.results.filter((document) => document.header.documentType === type);
|
|
16
|
+
// Create new paged results with filtered documents
|
|
17
|
+
// Note: This maintains the same paging structure but with filtered results
|
|
18
|
+
return {
|
|
19
|
+
results: filteredDocuments,
|
|
20
|
+
options: results.options,
|
|
21
|
+
nextCursor: results.nextCursor,
|
|
22
|
+
next: results.next
|
|
23
|
+
? async () => {
|
|
24
|
+
// If there's a next function, apply the same filter to the next page
|
|
25
|
+
const nextResults = await results.next();
|
|
26
|
+
return filterByType(nextResults, type);
|
|
27
|
+
}
|
|
28
|
+
: undefined,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAiC;AACjC,6DAA6D;AAC7D,QAAgB;IAEhB,mCAAmC;IACnC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAiC,EACjC,IAAY;IAEZ,0DAA0D;IAC1D,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAC9C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,KAAK,IAAI,CACpD,CAAC;IAEF,mDAAmD;IACnD,2EAA2E;IAC3E,OAAO;QACL,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;YAChB,CAAC,CAAC,KAAK,IAAI,EAAE;gBACT,qEAAqE;gBACrE,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,IAAK,EAAE,CAAC;gBAC1C,OAAO,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;YACH,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IEventBus } from "./interfaces.js";
|
|
2
|
-
import { Unsubscribe } from "./types.js";
|
|
1
|
+
import type { IEventBus } from "./interfaces.js";
|
|
2
|
+
import type { Subscriber, Unsubscribe } from "./types.js";
|
|
3
3
|
export declare class EventBus implements IEventBus {
|
|
4
|
-
|
|
4
|
+
readonly eventTypeToSubscribers: Map<number, Subscriber[]>;
|
|
5
5
|
subscribe<K>(type: number, subscriber: (type: number, event: K) => void | Promise<void>): Unsubscribe;
|
|
6
6
|
emit(type: number, data: any): Promise<void>;
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../src/events/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../src/events/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG1D,qBAAa,QAAS,YAAW,SAAS;IACxC,SAAgB,sBAAsB,4BAAmC;IAEzE,SAAS,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC3D,WAAW;IA8BR,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../src/events/event-bus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../src/events/event-bus.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,OAAO,QAAQ;IACH,sBAAsB,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEzE,SAAS,CACP,IAAY,EACZ,UAA4D;QAE5D,IAAI,IAAI,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,EAAE,CAAC;YACV,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAwB,CAAC,CAAC;QAEpC,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,OAAO,GAAG,EAAE;YACV,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YACD,IAAI,GAAG,IAAI,CAAC;YAEZ,MAAM,GAAG,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YAED,MAAM,GAAG,GAAG,GAAG,CAAC,OA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|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/events/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;OAQG;IACH,SAAS,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC3D,WAAW,CAAC;IAEf;;;;;;;;OAQG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C"}
|
|
@@ -19,6 +19,6 @@ export type Subscriber = (type: number, data: any) => void | Promise<void>;
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class EventBusAggregateError extends Error {
|
|
21
21
|
readonly errors: any[];
|
|
22
|
-
constructor(errors:
|
|
22
|
+
constructor(errors: unknown[]);
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3E;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAgB,MAAM,EAAE,GAAG,EAAE,CAAC;gBAElB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3E;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAgB,MAAM,EAAE,GAAG,EAAE,CAAC;gBAElB,MAAM,EAAE,OAAO,EAAE;CAc9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/B,MAAM,CAAQ;IAE9B,YAAY,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/B,MAAM,CAAQ;IAE9B,YAAY,MAAiB;QAC3B,MAAM,OAAO,GAAG,6BAA6B,MAAM,CAAC,MAAM,cAAc,MAAM;aAC3E,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;gBACjD,OAAQ,CAAW,CAAC,OAAO,CAAC;YAC9B,CAAC;YACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -1,72 +1,49 @@
|
|
|
1
|
-
import { Job } from "../queue/types.js";
|
|
2
|
-
import {
|
|
1
|
+
import type { Job } from "../queue/types.js";
|
|
2
|
+
import type { ExecutorManagerStatus, JobResult } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Simple interface for executing a job.
|
|
5
|
+
* A JobExecutor simply takes a job and executes it - nothing more.
|
|
6
6
|
*/
|
|
7
7
|
export interface IJobExecutor {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* Begins listening for 'jobAvailable' events from the event bus and executing jobs when capacity allows.
|
|
11
|
-
*
|
|
12
|
-
* @param config - Configuration options for the executor
|
|
13
|
-
* @returns Promise that resolves when the executor is started
|
|
14
|
-
*/
|
|
15
|
-
start(config?: JobExecutorConfig): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Stop the job executor.
|
|
18
|
-
* Gracefully stops listening for events and waits for current jobs to complete.
|
|
19
|
-
* @param graceful - Whether to wait for current jobs to complete
|
|
20
|
-
* @returns Promise that resolves when the executor is stopped
|
|
21
|
-
*/
|
|
22
|
-
stop(graceful?: boolean): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Execute a single job immediately.
|
|
9
|
+
* Execute a single job.
|
|
25
10
|
* @param job - The job to execute
|
|
26
11
|
* @returns Promise that resolves to the job result
|
|
27
12
|
*/
|
|
28
13
|
executeJob(job: Job): Promise<JobResult>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for managing multiple job executors.
|
|
17
|
+
* Listens for 'jobAvailable' events from the event bus, pulls jobs from the queue,
|
|
18
|
+
* and coordinates the distribution of jobs across multiple executor instances.
|
|
19
|
+
*/
|
|
20
|
+
export interface IJobExecutorManager {
|
|
29
21
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
activeJobs: number;
|
|
36
|
-
totalJobsProcessed: number;
|
|
37
|
-
totalJobsSucceeded: number;
|
|
38
|
-
totalJobsFailed: number;
|
|
39
|
-
lastJobCompletedAt?: string;
|
|
40
|
-
uptime?: number;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Get statistics about job execution performance.
|
|
44
|
-
* @returns Promise that resolves to execution statistics
|
|
22
|
+
* Start the executor manager.
|
|
23
|
+
* Begins listening for 'jobAvailable' events and dispatching to executors.
|
|
24
|
+
*
|
|
25
|
+
* @param numExecutors - Number of executor instances to create
|
|
26
|
+
* @returns Promise that resolves when the manager is started
|
|
45
27
|
*/
|
|
46
|
-
|
|
47
|
-
averageExecutionTime: number;
|
|
48
|
-
successRate: number;
|
|
49
|
-
jobsPerSecond: number;
|
|
50
|
-
queueBacklog: number;
|
|
51
|
-
}>;
|
|
28
|
+
start(numExecutors: number): Promise<void>;
|
|
52
29
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
30
|
+
* Stop the executor manager.
|
|
31
|
+
*
|
|
32
|
+
* @param graceful - Whether to wait for current jobs to complete
|
|
33
|
+
* @returns Promise that resolves when the manager is stopped
|
|
56
34
|
*/
|
|
57
|
-
|
|
35
|
+
stop(graceful?: boolean): Promise<void>;
|
|
58
36
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @returns
|
|
37
|
+
* Get all managed executor instances.
|
|
38
|
+
*
|
|
39
|
+
* @returns Array of executor instances
|
|
62
40
|
*/
|
|
63
|
-
|
|
41
|
+
getExecutors(): IJobExecutor[];
|
|
64
42
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
* @returns Function to unsubscribe from the event
|
|
43
|
+
* Get the current status of the manager.
|
|
44
|
+
*
|
|
45
|
+
* @returns The current manager status
|
|
69
46
|
*/
|
|
70
|
-
|
|
47
|
+
getStatus(): ExecutorManagerStatus;
|
|
71
48
|
}
|
|
72
49
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/executor/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/executor/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CAC1C;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3C;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExC;;;;OAIG;IACH,YAAY,IAAI,YAAY,EAAE,CAAC;IAE/B;;;;OAIG;IACH,SAAS,IAAI,qBAAqB,CAAC;CACpC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IEventBus } from "../events/interfaces.js";
|
|
2
|
+
import type { IQueue } from "../queue/interfaces.js";
|
|
3
|
+
import type { IJobExecutor, IJobExecutorManager } from "./interfaces.js";
|
|
4
|
+
import type { ExecutorManagerStatus } from "./types.js";
|
|
5
|
+
export type JobExecutorFactory = () => IJobExecutor;
|
|
6
|
+
/**
|
|
7
|
+
* Manages multiple job executors and coordinates job distribution.
|
|
8
|
+
* Listens for job available events and dispatches jobs to executors.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SimpleJobExecutorManager implements IJobExecutorManager {
|
|
11
|
+
private executorFactory;
|
|
12
|
+
private eventBus;
|
|
13
|
+
private queue;
|
|
14
|
+
private executors;
|
|
15
|
+
private isRunning;
|
|
16
|
+
private activeJobs;
|
|
17
|
+
private totalJobsProcessed;
|
|
18
|
+
private unsubscribe?;
|
|
19
|
+
constructor(executorFactory: JobExecutorFactory, eventBus: IEventBus, queue: IQueue);
|
|
20
|
+
start(numExecutors: number): Promise<void>;
|
|
21
|
+
stop(graceful?: boolean): Promise<void>;
|
|
22
|
+
getExecutors(): IJobExecutor[];
|
|
23
|
+
getStatus(): ExecutorManagerStatus;
|
|
24
|
+
private processNextJob;
|
|
25
|
+
private processExistingJobs;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=simple-job-executor-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-job-executor-manager.d.ts","sourceRoot":"","sources":["../../../src/executor/simple-job-executor-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAQhE,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,KAAK;IATf,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAa;gBAGvB,eAAe,EAAE,kBAAkB,EACnC,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,MAAM;IAGjB,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC1C,IAAI,CAAC,QAAQ,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB1C,YAAY,IAAI,YAAY,EAAE;IAI9B,SAAS,IAAI,qBAAqB;YASpB,cAAc;YA+Cd,mBAAmB;CAWlC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { QueueEventTypes } from "../queue/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Manages multiple job executors and coordinates job distribution.
|
|
4
|
+
* Listens for job available events and dispatches jobs to executors.
|
|
5
|
+
*/
|
|
6
|
+
export class SimpleJobExecutorManager {
|
|
7
|
+
executorFactory;
|
|
8
|
+
eventBus;
|
|
9
|
+
queue;
|
|
10
|
+
executors = [];
|
|
11
|
+
isRunning = false;
|
|
12
|
+
activeJobs = 0;
|
|
13
|
+
totalJobsProcessed = 0;
|
|
14
|
+
unsubscribe;
|
|
15
|
+
constructor(executorFactory, eventBus, queue) {
|
|
16
|
+
this.executorFactory = executorFactory;
|
|
17
|
+
this.eventBus = eventBus;
|
|
18
|
+
this.queue = queue;
|
|
19
|
+
}
|
|
20
|
+
async start(numExecutors) {
|
|
21
|
+
if (this.isRunning) {
|
|
22
|
+
throw new Error("JobExecutorManager is already running");
|
|
23
|
+
}
|
|
24
|
+
if (numExecutors < 1) {
|
|
25
|
+
throw new Error("Number of executors must be at least 1");
|
|
26
|
+
}
|
|
27
|
+
// Create executors
|
|
28
|
+
this.executors = [];
|
|
29
|
+
for (let i = 0; i < numExecutors; i++) {
|
|
30
|
+
this.executors.push(this.executorFactory());
|
|
31
|
+
}
|
|
32
|
+
// Start listening for job available events
|
|
33
|
+
this.unsubscribe = this.eventBus.subscribe(QueueEventTypes.JOB_AVAILABLE, async () => {
|
|
34
|
+
// Only process if we have capacity (simple round-robin for now)
|
|
35
|
+
if (this.activeJobs < this.executors.length) {
|
|
36
|
+
await this.processNextJob();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.isRunning = true;
|
|
40
|
+
// Process any existing jobs in the queue
|
|
41
|
+
await this.processExistingJobs();
|
|
42
|
+
}
|
|
43
|
+
async stop(graceful = true) {
|
|
44
|
+
if (!this.isRunning) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Stop listening for new jobs
|
|
48
|
+
if (this.unsubscribe) {
|
|
49
|
+
this.unsubscribe();
|
|
50
|
+
this.unsubscribe = undefined;
|
|
51
|
+
}
|
|
52
|
+
if (graceful) {
|
|
53
|
+
// Wait for active jobs to complete
|
|
54
|
+
while (this.activeJobs > 0) {
|
|
55
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.executors = [];
|
|
59
|
+
this.isRunning = false;
|
|
60
|
+
}
|
|
61
|
+
getExecutors() {
|
|
62
|
+
return [...this.executors];
|
|
63
|
+
}
|
|
64
|
+
getStatus() {
|
|
65
|
+
return {
|
|
66
|
+
isRunning: this.isRunning,
|
|
67
|
+
numExecutors: this.executors.length,
|
|
68
|
+
activeJobs: this.activeJobs,
|
|
69
|
+
totalJobsProcessed: this.totalJobsProcessed,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async processNextJob() {
|
|
73
|
+
try {
|
|
74
|
+
// Dequeue next available job
|
|
75
|
+
const handle = await this.queue.dequeueNext();
|
|
76
|
+
if (!handle) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.activeJobs++;
|
|
80
|
+
// Find an available executor (simple round-robin)
|
|
81
|
+
const executorIndex = this.totalJobsProcessed % this.executors.length;
|
|
82
|
+
const executor = this.executors[executorIndex];
|
|
83
|
+
// Execute the job
|
|
84
|
+
const result = await executor.executeJob(handle.job);
|
|
85
|
+
// Update job status in queue
|
|
86
|
+
if (result.success) {
|
|
87
|
+
await this.queue.completeJob(handle.job.id);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Handle retry logic
|
|
91
|
+
const retryCount = handle.job.retryCount || 0;
|
|
92
|
+
const maxRetries = handle.job.maxRetries || 0;
|
|
93
|
+
if (retryCount < maxRetries) {
|
|
94
|
+
await this.queue.retryJob(handle.job.id, result.error?.message);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
await this.queue.failJob(handle.job.id, result.error?.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.totalJobsProcessed++;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error("Error processing job:", error);
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
this.activeJobs--;
|
|
107
|
+
// Check if there are more jobs to process
|
|
108
|
+
if (this.isRunning) {
|
|
109
|
+
const hasMore = await this.queue.hasJobs();
|
|
110
|
+
if (hasMore) {
|
|
111
|
+
await this.processNextJob();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async processExistingJobs() {
|
|
117
|
+
const hasJobs = await this.queue.hasJobs();
|
|
118
|
+
if (hasJobs) {
|
|
119
|
+
// Start processing up to the number of executors
|
|
120
|
+
const promises = [];
|
|
121
|
+
for (let i = 0; i < Math.min(this.executors.length, 5); i++) {
|
|
122
|
+
promises.push(this.processNextJob());
|
|
123
|
+
}
|
|
124
|
+
await Promise.all(promises);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=simple-job-executor-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-job-executor-manager.js","sourceRoot":"","sources":["../../../src/executor/simple-job-executor-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMpD;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAQzB;IACA;IACA;IATF,SAAS,GAAmB,EAAE,CAAC;IAC/B,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,CAAC,CAAC;IACf,kBAAkB,GAAG,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AAC;QAC3C,IAAI,OAAO,EAAE,CAAC;YACZ,iDAAiD;YACjD,MAAM,QAAQ,GAAoB,EAAE,CAAC;YACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;YACvC,CAAC;YACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IDocumentOperationStorage, IDocumentStorage } from "document-drive";
|
|
2
|
+
import type { Job } from "../queue/types.js";
|
|
3
|
+
import type { IDocumentModelRegistry } from "../registry/interfaces.js";
|
|
4
|
+
import type { IJobExecutor } from "./interfaces.js";
|
|
5
|
+
import type { JobResult } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Simple job executor that processes a job by applying actions through document model reducers.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SimpleJobExecutor implements IJobExecutor {
|
|
10
|
+
private registry;
|
|
11
|
+
private documentStorage;
|
|
12
|
+
private operationStorage;
|
|
13
|
+
constructor(registry: IDocumentModelRegistry, documentStorage: IDocumentStorage, operationStorage: IDocumentOperationStorage);
|
|
14
|
+
/**
|
|
15
|
+
* Execute a single job by applying its action through the appropriate reducer.
|
|
16
|
+
*/
|
|
17
|
+
executeJob(job: Job): Promise<JobResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Execute a CREATE_DOCUMENT system action.
|
|
20
|
+
* This creates a new document in storage along with its initial operations.
|
|
21
|
+
*/
|
|
22
|
+
private executeCreateDocument;
|
|
23
|
+
/**
|
|
24
|
+
* Execute a DELETE_DOCUMENT system action.
|
|
25
|
+
* This deletes a document from storage.
|
|
26
|
+
*/
|
|
27
|
+
private executeDeleteDocument;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=simple-job-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-job-executor.d.ts","sourceRoot":"","sources":["../../../src/executor/simple-job-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAU5C;;GAEG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IAElD,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,gBAAgB;gBAFhB,QAAQ,EAAE,sBAAsB,EAChC,eAAe,EAAE,gBAAgB,EACjC,gBAAgB,EAAE,yBAAyB;IAGrD;;OAEG;IACG,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC;IAyE9C;;;OAGG;YACW,qBAAqB;IAmDnC;;;OAGG;YACW,qBAAqB;CA6CpC"}
|