@webda/async 3.9.3 → 4.0.0-beta.10

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 (41) hide show
  1. package/README.md +92 -8
  2. package/lib/asyncaction.model.d.ts +207 -0
  3. package/lib/asyncaction.model.d.ts.map +1 -0
  4. package/lib/asyncaction.model.js +269 -0
  5. package/lib/asyncaction.model.js.map +1 -0
  6. package/lib/index.d.ts +7 -5
  7. package/lib/index.d.ts.map +1 -0
  8. package/lib/index.js +6 -5
  9. package/lib/index.js.map +1 -1
  10. package/lib/services/asyncevents.service.d.ts +154 -0
  11. package/lib/services/asyncevents.service.d.ts.map +1 -0
  12. package/lib/services/asyncevents.service.js +219 -0
  13. package/lib/services/asyncevents.service.js.map +1 -0
  14. package/lib/services/{asyncjobservice.d.ts → asyncjobservice.service.d.ts} +81 -87
  15. package/lib/services/asyncjobservice.service.d.ts.map +1 -0
  16. package/lib/services/asyncjobservice.service.js +596 -0
  17. package/lib/services/asyncjobservice.service.js.map +1 -0
  18. package/lib/services/{localrunner.d.ts → localrunner.service.d.ts} +24 -9
  19. package/lib/services/localrunner.service.d.ts.map +1 -0
  20. package/lib/services/localrunner.service.js +87 -0
  21. package/lib/services/localrunner.service.js.map +1 -0
  22. package/lib/services/{runner.d.ts → runner.service.d.ts} +17 -11
  23. package/lib/services/runner.service.d.ts.map +1 -0
  24. package/lib/services/{runner.js → runner.service.js} +16 -13
  25. package/lib/services/runner.service.js.map +1 -0
  26. package/lib/services/{servicerunner.d.ts → servicerunner.service.d.ts} +39 -37
  27. package/lib/services/servicerunner.service.d.ts.map +1 -0
  28. package/lib/services/servicerunner.service.js +131 -0
  29. package/lib/services/servicerunner.service.js.map +1 -0
  30. package/package.json +35 -39
  31. package/webda.module.json +1910 -868
  32. package/lib/models.d.ts +0 -169
  33. package/lib/models.js +0 -177
  34. package/lib/models.js.map +0 -1
  35. package/lib/services/asyncjobservice.js +0 -521
  36. package/lib/services/asyncjobservice.js.map +0 -1
  37. package/lib/services/localrunner.js +0 -70
  38. package/lib/services/localrunner.js.map +0 -1
  39. package/lib/services/runner.js.map +0 -1
  40. package/lib/services/servicerunner.js +0 -152
  41. package/lib/services/servicerunner.js.map +0 -1
package/lib/models.d.ts DELETED
@@ -1,169 +0,0 @@
1
- import { CoreModel, OperationContext, WebContext } from "@webda/core";
2
- import { WorkerLogLevel } from "@webda/workout";
3
- /**
4
- * Represent an item for processing queue
5
- */
6
- export interface AsyncActionQueueItem {
7
- /**
8
- * Item to launch
9
- */
10
- uuid: string;
11
- /**
12
- * Secret key for status hook
13
- */
14
- __secretKey: string;
15
- /**
16
- * Type of action
17
- */
18
- type: string;
19
- }
20
- /**
21
- * Job information
22
- */
23
- export interface Job {
24
- }
25
- /**
26
- * Define here a model that can be used along with Store service
27
- * @WebdaModel
28
- */
29
- export default class AsyncAction extends CoreModel {
30
- /**
31
- * Set type
32
- */
33
- constructor();
34
- /**
35
- * By default AsyncAction are not considered internal
36
- *
37
- * Internal: That execute a method or operation of Webda application framework
38
- * @returns
39
- */
40
- isInternal(): boolean;
41
- /**
42
- * Action uuid
43
- */
44
- uuid: string;
45
- /**
46
- * Current status
47
- */
48
- status: "RUNNING" | "SUCCESS" | "ERROR" | "QUEUED" | "STARTING" | "TIMEOUT" | "SCHEDULED" | "CANCELLED";
49
- /**
50
- * Timestamp when the action was scheduled
51
- */
52
- scheduled?: number;
53
- /**
54
- * If an error occured it should contain the message
55
- */
56
- errorMessage?: string;
57
- /**
58
- * Job information
59
- */
60
- job: Job;
61
- /**
62
- * Last time the job was updated
63
- */
64
- _lastJobUpdate: number;
65
- /**
66
- * Results from the job
67
- */
68
- results: any;
69
- /**
70
- * Job current status
71
- */
72
- statusDetails: any;
73
- /**
74
- *
75
- */
76
- type: string;
77
- /**
78
- *
79
- */
80
- arguments?: any[];
81
- /**
82
- * Current logs
83
- */
84
- logs: string[];
85
- /**
86
- * Secret key to post feedback
87
- */
88
- __secretKey: string;
89
- /**
90
- * Expected action for the job
91
- *
92
- * It should be a verb
93
- */
94
- action?: "STOP" | string;
95
- getLogsLimit(): number;
96
- /**
97
- * Allow to report status for a job
98
- * @param context
99
- */
100
- statusAction(context: WebContext): Promise<void>;
101
- /**
102
- * Return the hook url if empty fallback to the service url
103
- * @returns
104
- */
105
- getHookUrl(): string;
106
- /**
107
- *
108
- * @param body
109
- */
110
- update(body: any, time?: string): Promise<this>;
111
- /**
112
- *
113
- * @param context
114
- * @param action
115
- */
116
- protected verifyJobRequest<K extends AsyncAction = AsyncAction>(context: WebContext): Promise<void>;
117
- /**
118
- * Get the hmac for the job
119
- * @param jobTime
120
- * @returns
121
- */
122
- getHmac(jobTime: string): string;
123
- /**
124
- * Ensure action hook is ok
125
- * @param context
126
- * @param _action
127
- * @returns
128
- */
129
- checkAct(context: OperationContext<any, any>, action: string): Promise<void>;
130
- }
131
- /**
132
- * Define a Webda Async Action
133
- *
134
- * @WebdaModel
135
- */
136
- export declare class AsyncWebdaAction extends AsyncAction {
137
- serviceName?: string;
138
- method?: string;
139
- logLevel: WorkerLogLevel;
140
- /**
141
- *
142
- * @param serviceName service to call
143
- * @param method method to call
144
- * @param arguments to call with the method
145
- */
146
- constructor(serviceName?: string, method?: string, ...args: any[]);
147
- /**
148
- * Execute a serviceName.method(...args) so this is internal
149
- * @returns
150
- */
151
- isInternal(): boolean;
152
- }
153
- /**
154
- * Operation called asynchronously
155
- *
156
- * @WebdaModel
157
- */
158
- export declare class AsyncOperationAction extends AsyncAction {
159
- operationId: string;
160
- context: OperationContext;
161
- logLevel: WorkerLogLevel;
162
- constructor(operationId: string, context: OperationContext, logLevel?: WorkerLogLevel);
163
- /**
164
- * Execute a webda.callOperation(context ,id) so this is internal
165
- * @returns
166
- */
167
- isInternal(): boolean;
168
- }
169
- export { AsyncAction };
package/lib/models.js DELETED
@@ -1,177 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Action, Core, CoreModel, WebContext, WebdaError } from "@webda/core";
8
- import * as crypto from "crypto";
9
- /**
10
- * Define here a model that can be used along with Store service
11
- * @WebdaModel
12
- */
13
- export default class AsyncAction extends CoreModel {
14
- /**
15
- * Set type
16
- */
17
- constructor() {
18
- super();
19
- this.type = this.constructor.name;
20
- }
21
- /**
22
- * By default AsyncAction are not considered internal
23
- *
24
- * Internal: That execute a method or operation of Webda application framework
25
- * @returns
26
- */
27
- isInternal() {
28
- return false;
29
- }
30
- getLogsLimit() {
31
- return 1000;
32
- }
33
- /**
34
- * Allow to report status for a job
35
- * @param context
36
- */
37
- async statusAction(context) {
38
- await this.update(await context.getRequestBody(), context.getHttpContext().getUniqueHeader("X-Job-Time"));
39
- context.write({ ...this, logs: undefined, statusDetails: undefined });
40
- }
41
- /**
42
- * Return the hook url if empty fallback to the service url
43
- * @returns
44
- */
45
- getHookUrl() {
46
- return Core.get().getApiUrl(`${Core.get().getRouter().getModelUrl(this)}/${this.uuid}`);
47
- }
48
- /**
49
- *
50
- * @param body
51
- */
52
- async update(body, time = undefined) {
53
- if (body.logs && Array.isArray(body.logs)) {
54
- this.logs ?? (this.logs = []);
55
- this.logs.push(...body.logs);
56
- // Prevent having too much logs
57
- if (this.logs.length > this.getLogsLimit()) {
58
- this.logs = this.logs.slice(-1 * this.getLogsLimit());
59
- }
60
- }
61
- this._lastJobUpdate = Number.parseInt(time || "0") || 0;
62
- if (Date.now() - this._lastJobUpdate > 60) {
63
- this._lastJobUpdate = Date.now();
64
- }
65
- await this.patch({
66
- _lastJobUpdate: this._lastJobUpdate,
67
- logs: this.logs,
68
- status: body.status || this.status,
69
- errorMessage: body.errorMessage || this.errorMessage,
70
- statusDetails: body.statusDetails || this.statusDetails,
71
- results: body.results || this.results
72
- });
73
- return this;
74
- }
75
- /**
76
- *
77
- * @param context
78
- * @param action
79
- */
80
- async verifyJobRequest(context) {
81
- const jobTime = context.getHttpContext().getUniqueHeader("X-Job-Time");
82
- const jobHash = context.getHttpContext().getUniqueHeader("X-Job-Hash");
83
- // Ensure hash mac is correct
84
- if (jobHash !== this.getHmac(jobTime)) {
85
- context.log("TRACE", "Invalid Job HMAC");
86
- throw new WebdaError.Forbidden("Invalid Job HMAC");
87
- }
88
- // Set the context extension
89
- context.setExtension("asyncJob", this);
90
- }
91
- /**
92
- * Get the hmac for the job
93
- * @param jobTime
94
- * @returns
95
- */
96
- getHmac(jobTime) {
97
- return crypto.createHmac("sha256", this.__secretKey).update(jobTime).digest("hex");
98
- }
99
- /**
100
- * Ensure action hook is ok
101
- * @param context
102
- * @param _action
103
- * @returns
104
- */
105
- async checkAct(context, action) {
106
- // Only action runner can call status action
107
- if ("status" === action) {
108
- if (context instanceof WebContext) {
109
- if (context.getHttpContext().getUniqueHeader("X-Job-Hash") &&
110
- context.getHttpContext().getUniqueHeader("X-Job-Time")) {
111
- return await this.verifyJobRequest(context);
112
- }
113
- }
114
- throw new WebdaError.Forbidden("Only Job runner can call this action");
115
- }
116
- // Allow to retrieve/update binaries by action runner
117
- if (["get_binary", "attach_binary", "update_binary_metadata"].includes(action) &&
118
- context.getHttpContext()?.getUniqueHeader("X-Job-Hash") &&
119
- context.getHttpContext()?.getUniqueHeader("X-Job-Time")) {
120
- console.log(action, context.getHttpContext()?.getUniqueHeader("X-Job-Hash"), context.getHttpContext()?.getUniqueHeader("X-Job-Time"));
121
- return await this.verifyJobRequest(context);
122
- }
123
- return super.checkAct(context, action);
124
- }
125
- }
126
- __decorate([
127
- Action({ name: "status", openapi: { hidden: true } })
128
- ], AsyncAction.prototype, "statusAction", null);
129
- /**
130
- * Define a Webda Async Action
131
- *
132
- * @WebdaModel
133
- */
134
- export class AsyncWebdaAction extends AsyncAction {
135
- /**
136
- *
137
- * @param serviceName service to call
138
- * @param method method to call
139
- * @param arguments to call with the method
140
- */
141
- constructor(serviceName, method, ...args) {
142
- super();
143
- this.serviceName = serviceName;
144
- this.method = method;
145
- this.logLevel = "INFO";
146
- this.arguments = args;
147
- }
148
- /**
149
- * Execute a serviceName.method(...args) so this is internal
150
- * @returns
151
- */
152
- isInternal() {
153
- return true;
154
- }
155
- }
156
- /**
157
- * Operation called asynchronously
158
- *
159
- * @WebdaModel
160
- */
161
- export class AsyncOperationAction extends AsyncAction {
162
- constructor(operationId, context, logLevel = "INFO") {
163
- super();
164
- this.operationId = operationId;
165
- this.context = context;
166
- this.logLevel = logLevel;
167
- }
168
- /**
169
- * Execute a webda.callOperation(context ,id) so this is internal
170
- * @returns
171
- */
172
- isInternal() {
173
- return true;
174
- }
175
- }
176
- export { AsyncAction };
177
- //# sourceMappingURL=models.js.map
package/lib/models.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAoB,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhG,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAyBjC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAAS;IAChD;;OAEG;IACH;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,UAAU;QACR,OAAO,KAAK,CAAC;IACf,CAAC;IAiED,YAAY;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IAEU,AAAN,KAAK,CAAC,YAAY,CAAC,OAAmB;QAC3C,MAAM,IAAI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