@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
@@ -1,152 +0,0 @@
1
- import { ConsoleLogger, MemoryLogger } from "@webda/workout";
2
- import { AsyncOperationAction, AsyncWebdaAction } from "../models.js";
3
- import { Runner, RunnerParameters } from "./runner.js";
4
- import { SimpleOperationContext } from "@webda/core";
5
- /**
6
- * Keep log in memory and save it to the action object every 5s
7
- *
8
- */
9
- export class ActionMemoryLogger extends MemoryLogger {
10
- /**
11
- *
12
- * @param output to connect to
13
- * @param level of logs
14
- * @param limit the size of the log
15
- * @param actionOrSaver the action to save the logs to or a function to save the logs
16
- * @param logSaveDelay delay before saving the logs
17
- * @param format format of the logs
18
- */
19
- constructor(output, level, limit, actionOrSaver, logSaveDelay, format) {
20
- super(output, level, limit);
21
- this.logSaveDelay = logSaveDelay;
22
- this.format = format;
23
- if (typeof actionOrSaver === "function") {
24
- this.saver = actionOrSaver;
25
- }
26
- else {
27
- this.saver = async (logs) => await actionOrSaver?.patch({ logs }, null);
28
- }
29
- }
30
- /**
31
- * @inheritdoc
32
- */
33
- onMessage(msg) {
34
- super.onMessage(msg);
35
- if (!this.timeout) {
36
- this.timeout = setTimeout(() => this.save(), this.logSaveDelay);
37
- }
38
- }
39
- /**
40
- * Save the logs to the action
41
- * @returns
42
- */
43
- save() {
44
- this.clearTimeout();
45
- return this.saver(this.getFormattedLogs());
46
- }
47
- /**
48
- * Clear the timeout
49
- */
50
- clearTimeout() {
51
- if (this.timeout) {
52
- clearTimeout(this.timeout);
53
- this.timeout = undefined;
54
- }
55
- }
56
- /**
57
- * Close the logger
58
- * @param clearTimeout clear the timeout
59
- * @returns
60
- */
61
- close(clearTimeout = false) {
62
- if (clearTimeout) {
63
- this.clearTimeout();
64
- }
65
- return super.close();
66
- }
67
- /**
68
- * Returns the formatted logs based on this.format
69
- * @returns
70
- */
71
- getFormattedLogs() {
72
- return this.getLogs().map(msg => ConsoleLogger.format(msg, this.format));
73
- }
74
- /**
75
- * Save the logs and close the logger
76
- * @returns
77
- */
78
- async saveAndClose() {
79
- this.close();
80
- return this.save();
81
- }
82
- }
83
- /**
84
- * Add the log format to capture
85
- */
86
- export class ServiceRunnerParameters extends RunnerParameters {
87
- constructor(params) {
88
- super(params);
89
- this.logSaveDelay ?? (this.logSaveDelay = 5000);
90
- }
91
- }
92
- /**
93
- * Run a Job locally on the server by spawning a child process
94
- *
95
- * @WebdaModda
96
- */
97
- export default class ServiceRunner extends Runner {
98
- /**
99
- * Load parameters
100
- * @param params
101
- * @returns
102
- */
103
- loadParameters(params) {
104
- return new ServiceRunnerParameters(params);
105
- }
106
- /**
107
- * @inheritdoc
108
- */
109
- async launchAction(action, info) {
110
- if (!(action instanceof AsyncWebdaAction || action instanceof AsyncOperationAction)) {
111
- this.log("ERROR", "Can only handle AsyncWebdaAction or AsyncOperationAction got", action.constructor.name);
112
- throw new Error("Can only handle AsyncWebdaAction or AsyncOperationAction got " + action.constructor.name);
113
- }
114
- // Launch within current process
115
- let promise = (async (action) => {
116
- let logger;
117
- try {
118
- await action.patch({ status: "RUNNING" });
119
- this.log("INFO", "Job", action.getUuid(), "started");
120
- // Inject a MemoryLogger to capture and report any logs
121
- logger = new ActionMemoryLogger(this.getWebda().getWorkerOutput(), action.logLevel, this.getService(info.JOB_ORCHESTRATOR)?.getParameters().logsLimit || 5000, action, this.parameters.logSaveDelay, this.parameters.logFormat);
122
- if (action instanceof AsyncWebdaAction) {
123
- await this.getService(action.serviceName)[action.method](...(action.arguments || []));
124
- }
125
- else {
126
- let ctx = new SimpleOperationContext(this.getWebda());
127
- // Unserialization might not have happened
128
- ctx.setSession(action.context.getSession ? action.context.getSession() : action.context["session"]);
129
- // Unserialization might not have happened
130
- ctx.setInput(Buffer.from(action.context["input"]?.data || []));
131
- await this.getWebda().callOperation(ctx, action.operationId);
132
- }
133
- await logger.saveAndClose();
134
- await action.patch({ status: "SUCCESS" }, null);
135
- this.log("INFO", "Job", action.getUuid(), "finished");
136
- }
137
- catch (err) {
138
- await logger?.saveAndClose();
139
- await action.patch({
140
- status: "ERROR",
141
- errorMessage: JSON.stringify(err, Object.getOwnPropertyNames(err))
142
- }, null);
143
- this.log("ERROR", "Job", action.getUuid(), "errored", err);
144
- }
145
- })(action);
146
- return {
147
- agent: Runner.getAgentInfo(),
148
- promise
149
- };
150
- }
151
- }
152
- //# sourceMappingURL=servicerunner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"servicerunner.js","sourceRoot":"","sources":["../../src/services/servicerunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAA+C,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAe,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAa,MAAM,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAkBrD;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAIlD;;;;;;;;OAQG;IACH,YACE,MAAoB,EACpB,KAAqB,EACrB,KAAa,EACb,aAAgE,EACzD,YAAoB,EACpB,MAAe;QAEtB,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAHrB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAS;QAGtB,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,KAAK,EAAE,IAAc,EAAE,EAAE,CAAC,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;QACpF,CAAC;IACH,CAAC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