@webiny/tasks 0.0.0-unstable.06b2ede40f

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 (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/context.d.ts +2 -0
  4. package/context.js +33 -0
  5. package/context.js.map +1 -0
  6. package/crud/crud.tasks.d.ts +2 -0
  7. package/crud/crud.tasks.js +273 -0
  8. package/crud/crud.tasks.js.map +1 -0
  9. package/crud/definition.tasks.d.ts +2 -0
  10. package/crud/definition.tasks.js +29 -0
  11. package/crud/definition.tasks.js.map +1 -0
  12. package/crud/model.d.ts +5 -0
  13. package/crud/model.js +216 -0
  14. package/crud/model.js.map +1 -0
  15. package/crud/service.tasks.d.ts +2 -0
  16. package/crud/service.tasks.js +171 -0
  17. package/crud/service.tasks.js.map +1 -0
  18. package/crud/where.d.ts +1 -0
  19. package/crud/where.js +33 -0
  20. package/crud/where.js.map +1 -0
  21. package/graphql/checkPermissions.d.ts +7 -0
  22. package/graphql/checkPermissions.js +46 -0
  23. package/graphql/checkPermissions.js.map +1 -0
  24. package/graphql/index.d.ts +2 -0
  25. package/graphql/index.js +351 -0
  26. package/graphql/index.js.map +1 -0
  27. package/graphql/utils.d.ts +9 -0
  28. package/graphql/utils.js +28 -0
  29. package/graphql/utils.js.map +1 -0
  30. package/handler/index.d.ts +6 -0
  31. package/handler/index.js +69 -0
  32. package/handler/index.js.map +1 -0
  33. package/handler/register.d.ts +1 -0
  34. package/handler/register.js +25 -0
  35. package/handler/register.js.map +1 -0
  36. package/handler/types.d.ts +25 -0
  37. package/handler/types.js +7 -0
  38. package/handler/types.js.map +1 -0
  39. package/index.d.ts +6 -0
  40. package/index.js +62 -0
  41. package/index.js.map +1 -0
  42. package/package.json +50 -0
  43. package/plugins/TaskServicePlugin.d.ts +20 -0
  44. package/plugins/TaskServicePlugin.js +17 -0
  45. package/plugins/TaskServicePlugin.js.map +1 -0
  46. package/plugins/index.d.ts +1 -0
  47. package/plugins/index.js +18 -0
  48. package/plugins/index.js.map +1 -0
  49. package/response/DatabaseResponse.d.ts +12 -0
  50. package/response/DatabaseResponse.js +152 -0
  51. package/response/DatabaseResponse.js.map +1 -0
  52. package/response/Response.d.ts +13 -0
  53. package/response/Response.js +120 -0
  54. package/response/Response.js.map +1 -0
  55. package/response/ResponseAbortedResult.d.ts +10 -0
  56. package/response/ResponseAbortedResult.js +19 -0
  57. package/response/ResponseAbortedResult.js.map +1 -0
  58. package/response/ResponseContinueResult.d.ts +18 -0
  59. package/response/ResponseContinueResult.js +26 -0
  60. package/response/ResponseContinueResult.js.map +1 -0
  61. package/response/ResponseDoneResult.d.ts +13 -0
  62. package/response/ResponseDoneResult.js +21 -0
  63. package/response/ResponseDoneResult.js.map +1 -0
  64. package/response/ResponseErrorResult.d.ts +11 -0
  65. package/response/ResponseErrorResult.js +20 -0
  66. package/response/ResponseErrorResult.js.map +1 -0
  67. package/response/TaskResponse.d.ts +11 -0
  68. package/response/TaskResponse.js +80 -0
  69. package/response/TaskResponse.js.map +1 -0
  70. package/response/abstractions/Response.d.ts +25 -0
  71. package/response/abstractions/Response.js +7 -0
  72. package/response/abstractions/Response.js.map +1 -0
  73. package/response/abstractions/ResponseAbortedResult.d.ts +5 -0
  74. package/response/abstractions/ResponseAbortedResult.js +7 -0
  75. package/response/abstractions/ResponseAbortedResult.js.map +1 -0
  76. package/response/abstractions/ResponseBaseResult.d.ts +8 -0
  77. package/response/abstractions/ResponseBaseResult.js +7 -0
  78. package/response/abstractions/ResponseBaseResult.js.map +1 -0
  79. package/response/abstractions/ResponseContinueResult.d.ts +21 -0
  80. package/response/abstractions/ResponseContinueResult.js +7 -0
  81. package/response/abstractions/ResponseContinueResult.js.map +1 -0
  82. package/response/abstractions/ResponseDoneResult.d.ts +14 -0
  83. package/response/abstractions/ResponseDoneResult.js +7 -0
  84. package/response/abstractions/ResponseDoneResult.js.map +1 -0
  85. package/response/abstractions/ResponseErrorResult.d.ts +19 -0
  86. package/response/abstractions/ResponseErrorResult.js +7 -0
  87. package/response/abstractions/ResponseErrorResult.js.map +1 -0
  88. package/response/abstractions/TaskResponse.d.ts +38 -0
  89. package/response/abstractions/TaskResponse.js +7 -0
  90. package/response/abstractions/TaskResponse.js.map +1 -0
  91. package/response/abstractions/index.d.ts +7 -0
  92. package/response/abstractions/index.js +84 -0
  93. package/response/abstractions/index.js.map +1 -0
  94. package/response/index.d.ts +7 -0
  95. package/response/index.js +84 -0
  96. package/response/index.js.map +1 -0
  97. package/runner/TaskControl.d.ts +14 -0
  98. package/runner/TaskControl.js +222 -0
  99. package/runner/TaskControl.js.map +1 -0
  100. package/runner/TaskEventValidation.d.ts +5 -0
  101. package/runner/TaskEventValidation.js +30 -0
  102. package/runner/TaskEventValidation.js.map +1 -0
  103. package/runner/TaskManager.d.ts +14 -0
  104. package/runner/TaskManager.js +139 -0
  105. package/runner/TaskManager.js.map +1 -0
  106. package/runner/TaskManagerStore.d.ts +40 -0
  107. package/runner/TaskManagerStore.js +167 -0
  108. package/runner/TaskManagerStore.js.map +1 -0
  109. package/runner/TaskRunner.d.ts +26 -0
  110. package/runner/TaskRunner.js +97 -0
  111. package/runner/TaskRunner.js.map +1 -0
  112. package/runner/abstractions/TaskControl.d.ts +10 -0
  113. package/runner/abstractions/TaskControl.js +7 -0
  114. package/runner/abstractions/TaskControl.js.map +1 -0
  115. package/runner/abstractions/TaskEventValidation.d.ts +5 -0
  116. package/runner/abstractions/TaskEventValidation.js +7 -0
  117. package/runner/abstractions/TaskEventValidation.js.map +1 -0
  118. package/runner/abstractions/TaskManager.d.ts +5 -0
  119. package/runner/abstractions/TaskManager.js +7 -0
  120. package/runner/abstractions/TaskManager.js.map +1 -0
  121. package/runner/abstractions/TaskManagerStore.d.ts +92 -0
  122. package/runner/abstractions/TaskManagerStore.js +7 -0
  123. package/runner/abstractions/TaskManagerStore.js.map +1 -0
  124. package/runner/abstractions/TaskRunner.d.ts +13 -0
  125. package/runner/abstractions/TaskRunner.js +7 -0
  126. package/runner/abstractions/TaskRunner.js.map +1 -0
  127. package/runner/abstractions/index.d.ts +5 -0
  128. package/runner/abstractions/index.js +62 -0
  129. package/runner/abstractions/index.js.map +1 -0
  130. package/runner/index.d.ts +1 -0
  131. package/runner/index.js +18 -0
  132. package/runner/index.js.map +1 -0
  133. package/service/EventBridgeEventTransportPlugin.d.ts +17 -0
  134. package/service/EventBridgeEventTransportPlugin.js +60 -0
  135. package/service/EventBridgeEventTransportPlugin.js.map +1 -0
  136. package/service/StepFunctionServicePlugin.d.ts +26 -0
  137. package/service/StepFunctionServicePlugin.js +88 -0
  138. package/service/StepFunctionServicePlugin.js.map +1 -0
  139. package/service/createService.d.ts +6 -0
  140. package/service/createService.js +30 -0
  141. package/service/createService.js.map +1 -0
  142. package/service/index.d.ts +4 -0
  143. package/service/index.js +31 -0
  144. package/service/index.js.map +1 -0
  145. package/task/index.d.ts +2 -0
  146. package/task/index.js +29 -0
  147. package/task/index.js.map +1 -0
  148. package/task/input.d.ts +15 -0
  149. package/task/input.js +21 -0
  150. package/task/input.js.map +1 -0
  151. package/task/plugin.d.ts +36 -0
  152. package/task/plugin.js +106 -0
  153. package/task/plugin.js.map +1 -0
  154. package/tasks/testingRunTask.d.ts +1 -0
  155. package/tasks/testingRunTask.js +21 -0
  156. package/tasks/testingRunTask.js.map +1 -0
  157. package/types.d.ts +340 -0
  158. package/types.js +69 -0
  159. package/types.js.map +1 -0
  160. package/utils/ObjectUpdater.d.ts +8 -0
  161. package/utils/ObjectUpdater.js +46 -0
  162. package/utils/ObjectUpdater.js.map +1 -0
  163. package/utils/getErrorProperties.d.ts +2 -0
  164. package/utils/getErrorProperties.js +15 -0
  165. package/utils/getErrorProperties.js.map +1 -0
  166. package/utils/getObjectProperties.d.ts +8 -0
  167. package/utils/getObjectProperties.js +25 -0
  168. package/utils/getObjectProperties.js.map +1 -0
  169. package/utils/index.d.ts +3 -0
  170. package/utils/index.js +40 -0
  171. package/utils/index.js.map +1 -0
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TaskManagerStore = void 0;
8
+ var _types = require("../types");
9
+ var _deepEqual = _interopRequireDefault(require("deep-equal"));
10
+ var _getObjectProperties = require("../utils/getObjectProperties");
11
+ var _ObjectUpdater = require("../utils/ObjectUpdater");
12
+ /**
13
+ * Package deep-equal does not have types.
14
+ */
15
+
16
+ const getInput = (originalInput, input) => {
17
+ if (typeof input === "function") {
18
+ return input(originalInput);
19
+ }
20
+ return {
21
+ ...originalInput,
22
+ ...input
23
+ };
24
+ };
25
+ class TaskManagerStore {
26
+ taskUpdater = new _ObjectUpdater.ObjectUpdater();
27
+ taskLogUpdater = new _ObjectUpdater.ObjectUpdater();
28
+ constructor(params) {
29
+ this.context = params.context;
30
+ this.task = params.task;
31
+ this.taskLog = params.log;
32
+ this.disableDatabaseLogs = !!params.disableDatabaseLogs;
33
+ }
34
+ getStatus() {
35
+ return this.task.taskStatus;
36
+ }
37
+ getTask() {
38
+ return this.task;
39
+ }
40
+ async listChildTasks(definitionId) {
41
+ const where = {
42
+ parentId: this.task.id
43
+ };
44
+ if (definitionId) {
45
+ where.definitionId = definitionId;
46
+ }
47
+ const result = await this.context.tasks.listTasks({
48
+ where,
49
+ sort: ["createdOn_ASC"],
50
+ limit: 1000000
51
+ });
52
+ return result.items;
53
+ }
54
+ async updateTask(param, options) {
55
+ const data = typeof param === "function" ? param(this.task) : param;
56
+
57
+ /**
58
+ * No need to update if nothing changed.
59
+ */
60
+ if ((0, _deepEqual.default)(data, this.task)) {
61
+ return;
62
+ }
63
+ this.taskUpdater.update(data);
64
+ if (options?.save === false) {
65
+ return;
66
+ }
67
+ await this.save();
68
+ }
69
+ async updateInput(param, options) {
70
+ const input = getInput(this.task.input, param);
71
+
72
+ /**
73
+ * No need to update if nothing changed.
74
+ */
75
+ if ((0, _deepEqual.default)(input, this.task.input)) {
76
+ return;
77
+ }
78
+ this.taskUpdater.update({
79
+ input: input
80
+ });
81
+ if (options?.save === false) {
82
+ return;
83
+ }
84
+ await this.save();
85
+ }
86
+ getInput() {
87
+ return this.task.input;
88
+ }
89
+ async updateOutput(values, options = {}) {
90
+ this.taskUpdater.update({
91
+ output: values
92
+ });
93
+ if (options?.save === false) {
94
+ return;
95
+ }
96
+ await this.save();
97
+ }
98
+ getOutput() {
99
+ return this.task.output;
100
+ }
101
+ /**
102
+ * Currently the methods throws an error if something goes wrong during the database update.
103
+ * TODO: Maybe we should wrap it into try/catch and return error if any?
104
+ */
105
+ async addInfoLog(log, options) {
106
+ if (this.disableDatabaseLogs) {
107
+ return;
108
+ }
109
+ this.taskLogUpdater.update({
110
+ items: [{
111
+ message: log.message,
112
+ data: log.data,
113
+ type: _types.TaskLogItemType.INFO,
114
+ createdOn: new Date().toISOString()
115
+ }]
116
+ });
117
+ if (options?.save === false) {
118
+ return;
119
+ }
120
+ await this.save();
121
+ }
122
+ /**
123
+ * Currently the methods throws an error if something goes wrong during the database update.
124
+ * TODO: Maybe we should wrap it into try/catch and return error if any?
125
+ */
126
+ async addErrorLog(log, options) {
127
+ if (this.disableDatabaseLogs) {
128
+ return;
129
+ }
130
+ /**
131
+ * Let's log the error to the console as well.
132
+ */
133
+ console.error(log.error);
134
+ /**
135
+ * Then update the log object.
136
+ */
137
+ this.taskLogUpdater.update({
138
+ items: [{
139
+ message: log.message,
140
+ error: log.error instanceof Error ? (0, _getObjectProperties.getObjectProperties)(log.error) : log.error,
141
+ type: _types.TaskLogItemType.ERROR,
142
+ createdOn: new Date().toISOString()
143
+ }]
144
+ });
145
+ if (options?.save === false) {
146
+ return;
147
+ }
148
+ await this.save();
149
+ }
150
+ async save() {
151
+ /**
152
+ * Update both task and the log, if anything to update.
153
+ */
154
+ if (this.taskUpdater.isDirty()) {
155
+ this.task = await this.context.tasks.updateTask(this.task.id, this.taskUpdater.fetch());
156
+ }
157
+ if (this.disableDatabaseLogs) {
158
+ return;
159
+ }
160
+ if (this.taskLogUpdater.isDirty()) {
161
+ this.taskLog = await this.context.tasks.updateLog(this.taskLog.id, this.taskLogUpdater.fetch());
162
+ }
163
+ }
164
+ }
165
+ exports.TaskManagerStore = TaskManagerStore;
166
+
167
+ //# sourceMappingURL=TaskManagerStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_types","require","_deepEqual","_interopRequireDefault","_getObjectProperties","_ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","ObjectUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","disableDatabaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","deepEqual","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","TaskLogItemType","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","getObjectProperties","ERROR","isDirty","fetch","updateLog","exports"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITaskResponseDoneResultOutput,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types\";\nimport { TaskLogItemType } from \"~/types\";\nimport type {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions\";\n/**\n * Package deep-equal does not have types.\n */\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n disableDatabaseLogs?: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly disableDatabaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.disableDatabaseLogs = !!params.disableDatabaseLogs;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (this.disableDatabaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AALA;AACA;AACA;;AAMA,MAAMK,QAAQ,GAAGA,CACbC,aAAgB,EAChBC,KAA+C,KAC3C;EACJ,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;IAC7B,OAAOA,KAAK,CAACD,aAAa,CAAC;EAC/B;EACA,OAAO;IACH,GAAGA,aAAa;IAChB,GAAGC;EACP,CAAC;AACL,CAAC;AAaM,MAAMC,gBAAgB,CAI7B;EAMqBC,WAAW,GAAG,IAAIC,4BAAa,CAAc,CAAC;EAC9CC,cAAc,GAAG,IAAID,4BAAa,CAAW,CAAC;EAExDE,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,IAAI,GAAGF,MAAM,CAACE,IAAmB;IACtC,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACI,GAAG;IACzB,IAAI,CAACC,mBAAmB,GAAG,CAAC,CAACL,MAAM,CAACK,mBAAmB;EAC3D;EAEOC,SAASA,CAAA,EAAmB;IAC/B,OAAO,IAAI,CAACJ,IAAI,CAACK,UAAU;EAC/B;EAEOC,OAAOA,CAAA,EAAgB;IAC1B,OAAO,IAAI,CAACN,IAAI;EACpB;EAEA,MAAaO,cAAcA,CAGzBC,YAAqB,EAA0B;IAC7C,MAAMC,KAA2B,GAAG;MAChCC,Q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B,GAAG,CAAC6B,OAAO;QACpBS,KAAK,EAAEtC,GAAG,CAACsC,KAAK,YAAYC,KAAK,GAAG,IAAAC,wCAAmB,EAACxC,GAAG,CAACsC,KAAK,CAAC,GAAGtC,GAAG,CAACsC,KAAK;QAC9ER,IAAI,EAAEC,sBAAe,CAACU,KAAK;QAC3BR,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC;MACtC,CAAC;IAET,CAAC,CAAC;IACF,IAAIjB,OAAO,EAAEI,IAAI,KAAK,KAAK,EAAE;MACzB;IACJ;IACA,MAAM,IAAI,CAACA,IAAI,CAAC,CAAC;EACrB;EAEA,MAAaA,IAAIA,CAAA,EAAkB;IAC/B;AACR;AACA;IACQ,IAAI,IAAI,CAAC9B,WAAW,CAACkD,OAAO,CAAC,CAAC,EAAE;MAC5B,IAAI,CAAC5C,IAAI,GAAG,MAAM,IAAI,CAACD,OAAO,CAACc,KAAK,CAACK,UAAU,CAC3C,IAAI,CAAClB,IAAI,CAACW,EAAE,EACZ,IAAI,CAACjB,WAAW,CAACmD,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,IAAI,CAAC1C,mBAAmB,EAAE;MAC1B;IACJ;IACA,IAAI,IAAI,CAACP,cAAc,CAACgD,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAAC3C,OAAO,GAAG,MAAM,IAAI,CAACF,OAAO,CAACc,KAAK,CAACiC,SAAS,CAC7C,IAAI,CAAC7C,OAAO,CAACU,EAAE,EACf,IAAI,CAACf,cAAc,CAACiD,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ;AAACE,OAAA,CAAAtD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import type { ITaskRawEvent } from "../handler/types";
2
+ import type { ITaskEventValidation, ITaskRunner } from "./abstractions";
3
+ import type { Context } from "../types";
4
+ import type { IResponseResult } from "../response/abstractions";
5
+ import type { ITimer } from "@webiny/handler-aws/utils";
6
+ export declare class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {
7
+ /**
8
+ * When DI is introduced, these will get injected.
9
+ *
10
+ * container.bind<Request>("Request").toConstantValue(request);
11
+ * @inject("Request") public readonly request: Request;
12
+ *
13
+ * Follow the same example for the rest of the properties.
14
+ */
15
+ readonly context: C;
16
+ readonly timer: ITimer;
17
+ private readonly validation;
18
+ /**
19
+ * We take all required variables separately because they will get injected via DI - so less refactoring is required in the future.
20
+ */
21
+ constructor(context: C, timer: ITimer, validation: ITaskEventValidation);
22
+ isCloseToTimeout(seconds?: number): boolean;
23
+ run(rawEvent: ITaskRawEvent): Promise<IResponseResult>;
24
+ private getIsCloseToTimeoutMilliseconds;
25
+ private setLocale;
26
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TaskRunner = void 0;
7
+ var _response = require("../response");
8
+ var _TaskControl = require("./TaskControl");
9
+ var _getErrorProperties = require("../utils/getErrorProperties");
10
+ const transformMinutesIntoMilliseconds = minutes => {
11
+ return minutes * 60000;
12
+ };
13
+ const DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;
14
+ class TaskRunner {
15
+ /**
16
+ * When DI is introduced, these will get injected.
17
+ *
18
+ * container.bind<Request>("Request").toConstantValue(request);
19
+ * @inject("Request") public readonly request: Request;
20
+ *
21
+ * Follow the same example for the rest of the properties.
22
+ */
23
+
24
+ /**
25
+ * We take all required variables separately because they will get injected via DI - so less refactoring is required in the future.
26
+ */
27
+ constructor(context, timer, validation) {
28
+ this.context = context;
29
+ this.timer = timer;
30
+ this.validation = validation;
31
+ }
32
+ isCloseToTimeout(seconds) {
33
+ const milliseconds = seconds ? seconds * 1000 : this.getIsCloseToTimeoutMilliseconds();
34
+ return this.timer.getRemainingMilliseconds() < milliseconds;
35
+ }
36
+ async run(rawEvent) {
37
+ const response = new _response.Response({
38
+ ...rawEvent
39
+ });
40
+ let event;
41
+ try {
42
+ event = this.validation.validate(rawEvent);
43
+ } catch (ex) {
44
+ return response.error({
45
+ error: (0, _getErrorProperties.getErrorProperties)(ex)
46
+ });
47
+ }
48
+ response.setEvent(event);
49
+ /**
50
+ * If we received a delay when initiating the task, we need to send the continue response immediately.
51
+ */
52
+ if (rawEvent.delay && rawEvent.delay > 0) {
53
+ return response.continue({
54
+ input: {},
55
+ wait: rawEvent.delay
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Here we set the context locale, using the value receive from the event.
61
+ */
62
+ this.setLocale(event);
63
+ const control = new _TaskControl.TaskControl(this, response, this.context);
64
+ try {
65
+ const result = await control.run(event);
66
+ if (result instanceof _response.ResponseErrorResult === false) {
67
+ return result;
68
+ }
69
+ console.error(result);
70
+ return result;
71
+ } catch (ex) {
72
+ console.error(`Failed to execute task "${event.webinyTaskId}".`);
73
+ console.error(ex);
74
+ return response.error({
75
+ error: (0, _getErrorProperties.getErrorProperties)(ex)
76
+ });
77
+ }
78
+ }
79
+ getIsCloseToTimeoutMilliseconds() {
80
+ const value = parseInt(process.env["WEBINY_TASKS_TIMEOUT_CLOSE_MINUTES"] || "");
81
+ const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;
82
+ return transformMinutesIntoMilliseconds(result);
83
+ }
84
+ setLocale(event) {
85
+ const {
86
+ locale: localeCode
87
+ } = event;
88
+ const locale = this.context.i18n.getLocale(localeCode);
89
+ if (!locale) {
90
+ return;
91
+ }
92
+ this.context.i18n.setContentLocale(locale);
93
+ }
94
+ }
95
+ exports.TaskRunner = TaskRunner;
96
+
97
+ //# sourceMappingURL=TaskRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_response","require","_TaskControl","_getErrorProperties","transformMinutesIntoMilliseconds","minutes","DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES","TaskRunner","constructor","context","timer","validation","isCloseToTimeout","seconds","milliseconds","getIsCloseToTimeoutMilliseconds","getRemainingMilliseconds","run","rawEvent","response","Response","event","validate","ex","error","getErrorProperties","setEvent","delay","continue","input","wait","setLocale","control","TaskControl","result","ResponseErrorResult","console","webinyTaskId","value","parseInt","process","env","locale","localeCode","i18n","getLocale","setContentLocale","exports"],"sources":["TaskRunner.ts"],"sourcesContent":["import type { ITaskEvent, ITaskRawEvent } from \"~/handler/types\";\nimport type { ITaskEventValidation, ITaskRunner } from \"./abstractions\";\nimport type { Context } from \"~/types\";\nimport { Response, ResponseErrorResult } from \"~/response\";\nimport { TaskControl } from \"./TaskControl\";\nimport type { IResponseResult } from \"~/response/abstractions\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties\";\nimport type { ITimer } from \"@webiny/handler-aws/utils\";\n\nconst transformMinutesIntoMilliseconds = (minutes: number) => {\n return minutes * 60000;\n};\n\nconst DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;\n\nexport class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {\n /**\n * When DI is introduced, these will get injected.\n *\n * container.bind<Request>(\"Request\").toConstantValue(request);\n * @inject(\"Request\") public readonly request: Request;\n *\n * Follow the same example for the rest of the properties.\n */\n public readonly context: C;\n public readonly timer: ITimer;\n private readonly validation: ITaskEventValidation;\n\n /**\n * We take all required variables separately because they will get injected via DI - so less refactoring is required in the future.\n */\n public constructor(context: C, timer: ITimer, validation: ITaskEventValidation) {\n this.context = context;\n this.timer = timer;\n this.validation = validation;\n }\n\n public isCloseToTimeout(seconds?: number) {\n const milliseconds = seconds ? seconds * 1000 : this.getIsCloseToTimeoutMilliseconds();\n return this.timer.getRemainingMilliseconds() < milliseconds;\n }\n\n public async run(rawEvent: ITaskRawEvent): Promise<IResponseResult> {\n const response = new Response({\n ...rawEvent\n });\n\n let event: ITaskEvent;\n try {\n event = this.validation.validate(rawEvent);\n } catch (ex) {\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n response.setEvent(event);\n /**\n * If we received a delay when initiating the task, we need to send the continue response immediately.\n */\n if (rawEvent.delay && rawEvent.delay > 0) {\n return response.continue({\n input: {},\n wait: rawEvent.delay\n });\n }\n\n /**\n * Here we set the context locale, using the value receive from the event.\n */\n this.setLocale(event);\n\n const control = new TaskControl(this, response, this.context);\n\n try {\n const result = await control.run(event);\n if (result instanceof ResponseErrorResult === false) {\n return result;\n }\n console.error(result);\n return result;\n } catch (ex) {\n console.error(`Failed to execute task \"${event.webinyTaskId}\".`);\n console.error(ex);\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n }\n\n private getIsCloseToTimeoutMilliseconds() {\n const value = parseInt(process.env[\"WEBINY_TASKS_TIMEOUT_CLOSE_MINUTES\"] || \"\");\n const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;\n return transformMinutesIntoMilliseconds(result);\n }\n\n private setLocale(event: ITaskEvent) {\n const { locale: localeCode } = event;\n const locale = this.context.i18n.getLocale(localeCode);\n\n if (!locale) {\n return;\n }\n\n this.context.i18n.setContentLocale(locale);\n }\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AAGA,MAAMG,gCAAgC,GAAIC,OAAe,IAAK;EAC1D,OAAOA,OAAO,GAAG,KAAK;AAC1B,CAAC;AAED,MAAMC,mCAAmC,GAAG,CAAC;AAEtC,MAAMC,UAAU,CAAwD;EAC3E;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;EAKI;AACJ;AACA;EACWC,WAAWA,CAACC,OAAU,EAAEC,KAAa,EAAEC,UAAgC,EAAE;IAC5E,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,UAAU,GAAGA,UAAU;EAChC;EAEOC,gBAAgBA,CAACC,OAAgB,EAAE;IACtC,MAAMC,YAAY,GAAGD,OAAO,GAAGA,OAAO,GAAG,IAAI,GAAG,IAAI,CAACE,+BAA+B,CAAC,CAAC;IAC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E,CAAC;MACjB,OAAOJ,QAAQ,CAACK,KAAK,CAAC;QAClBA,KAAK,EAAE,IAAAC,sCAAkB,EAACF,EAAE;MAChC,CAAC,CAAC;IACN;EACJ;EAEQR,+BAA+BA,CAAA,EAAG;IACtC,MAAMuB,KAAK,GAAGC,QAAQ,CAACC,OAAO,CAACC,GAAG,CAAC,oCAAoC,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAMP,MAAM,GAAGI,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAGhC,mCAAmC;IACtE,OAAOF,gCAAgC,CAAC8B,MAAM,CAAC;EACnD;EAEQH,SAASA,CAACV,KAAiB,EAAE;IACjC,MAAM;MAAEqB,MAAM,EAAEC;IAAW,CAAC,GAAGtB,KAAK;IACpC,MAAMqB,MAAM,GAAG,IAAI,CAACjC,OAAO,CAACmC,IAAI,CAACC,SAAS,CAACF,UAAU,CAAC;IAEtD,IAAI,CAACD,MAAM,EAAE;MACT;IACJ;IAEA,IAAI,CAACjC,OAAO,CAACmC,IAAI,CAACE,gBAAgB,CAACJ,MAAM,CAAC;EAC9C;AACJ;AAACK,OAAA,CAAAxC,UAAA,GAAAA,UAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { ITaskRunner } from "./";
2
+ import type { IResponse, IResponseResult } from "../../response/abstractions";
3
+ import type { Context } from "../../types";
4
+ import type { ITaskEvent } from "../../handler/types";
5
+ export interface ITaskControl {
6
+ runner: ITaskRunner;
7
+ response: IResponse;
8
+ context: Context;
9
+ run(event: ITaskEvent): Promise<IResponseResult>;
10
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=TaskControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["TaskControl.ts"],"sourcesContent":["import type { ITaskRunner } from \"~/runner/abstractions\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions\";\nimport type { Context } from \"~/types\";\nimport type { ITaskEvent } from \"~/handler/types\";\n\nexport interface ITaskControl {\n runner: ITaskRunner;\n response: IResponse;\n context: Context;\n\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ import type { ITaskEvent } from "../../handler/types";
2
+ export type ITaskEventValidationResult = ITaskEvent;
3
+ export interface ITaskEventValidation {
4
+ validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;
5
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=TaskEventValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["TaskEventValidation.ts"],"sourcesContent":["import type { ITaskEvent } from \"~/handler/types\";\n\nexport type ITaskEventValidationResult = ITaskEvent;\n\nexport interface ITaskEventValidation {\n validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ import type { IResponseResult } from "../../response/abstractions";
2
+ import type { ITask, ITaskDataInput, ITaskDefinition } from "../../types";
3
+ export interface ITaskManager<T = ITaskDataInput> {
4
+ run: (definition: ITaskDefinition, task: ITask<T>) => Promise<IResponseResult>;
5
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=TaskManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["TaskManager.ts"],"sourcesContent":["import type { IResponseResult } from \"~/response/abstractions\";\nimport type { ITask, ITaskDataInput, ITaskDefinition } from \"~/types\";\n\nexport interface ITaskManager<T = ITaskDataInput> {\n run: (definition: ITaskDefinition, task: ITask<T>) => Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,92 @@
1
+ import type { IResponseError, ITask, ITaskDataInput, ITaskLogItemData, ITaskResponseDoneResultOutput, ITaskUpdateData, TaskDataStatus } from "../../types";
2
+ import type { GenericRecord } from "@webiny/api/types";
3
+ export type ITaskManagerStoreUpdateTaskValues<T = ITaskDataInput> = T;
4
+ export interface ITaskManagerStoreUpdateTaskValuesCb<T = ITaskDataInput> {
5
+ (input: T): T;
6
+ }
7
+ export interface ITaskManagerStoreUpdateTaskInputOptions {
8
+ save: boolean;
9
+ }
10
+ export type ITaskManagerStoreUpdateTaskInputParam<T = ITaskDataInput> = ITaskManagerStoreUpdateTaskValuesCb<T> | Partial<ITaskManagerStoreUpdateTaskValues<T>>;
11
+ export interface ITaskManagerStoreUpdateTaskParamCb<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
12
+ (task: ITask<T, O>): ITaskUpdateData<T, O>;
13
+ }
14
+ export type ITaskManagerStoreUpdateTask<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskUpdateData<T, O>;
15
+ export type ITaskManagerStoreUpdateTaskParams<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;
16
+ export interface ITaskManagerStoreInfoLog {
17
+ message: string;
18
+ data?: ITaskLogItemData;
19
+ }
20
+ export interface ITaskManagerStoreErrorLog {
21
+ message: string;
22
+ data?: ITaskLogItemData;
23
+ error: IResponseError | Error;
24
+ }
25
+ export interface ITaskManagerStoreSetOutputOptions {
26
+ /**
27
+ * Default is true.
28
+ */
29
+ save?: boolean;
30
+ }
31
+ export interface ITaskManagerStoreUpdateTaskOptions {
32
+ /**
33
+ * Default is true.
34
+ */
35
+ save?: boolean;
36
+ }
37
+ export interface ITaskManagerStoreAddLogOptions {
38
+ /**
39
+ * Default is true.
40
+ */
41
+ save?: boolean;
42
+ }
43
+ /**
44
+ * Interface should not be used outside the @webiny/tasks package.
45
+ */
46
+ export interface ITaskManagerStorePrivate<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
47
+ getTask: () => ITask<T, O>;
48
+ getStatus: () => TaskDataStatus;
49
+ /**
50
+ * @throws {Error} If task not found or something goes wrong during the database update.
51
+ */
52
+ updateTask(params: ITaskManagerStoreUpdateTaskParams<T, O>, options?: ITaskManagerStoreUpdateTaskOptions): Promise<void>;
53
+ /**
54
+ * List all child tasks of the current task.
55
+ * If definitionId is provided, filter by that parameter.
56
+ */
57
+ listChildTasks<T = GenericRecord, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput>(definitionId?: string): Promise<ITask<T, O>[]>;
58
+ /**
59
+ * Update the task input, which are used to store custom user data.
60
+ * You can send partial input, and it will be merged with the existing input.
61
+ *
62
+ * @throws {Error} If task not found or something goes wrong during the database update.
63
+ */
64
+ updateInput: (params: ITaskManagerStoreUpdateTaskInputParam<T>, options?: ITaskManagerStoreUpdateTaskInputOptions) => Promise<void>;
65
+ getInput: () => T;
66
+ /**
67
+ * Update the task output, which are used to store the output data.
68
+ * You can send partial output, and it will be merged with the existing output.
69
+ *
70
+ * Second parameter is optional options, and it contains a possibility not to store the task immediately.
71
+ *
72
+ * @throws {Error} If task not found or something goes wrong during the database update.
73
+ */
74
+ updateOutput: (values: Partial<O>, options?: ITaskManagerStoreSetOutputOptions) => Promise<void>;
75
+ getOutput: () => O;
76
+ /**
77
+ * @throws {Error} If task not found or something goes wrong during the database update.
78
+ */
79
+ addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise<void>;
80
+ /**
81
+ * @throws {Error} If task not found or something goes wrong during the database update.
82
+ *
83
+ *
84
+ */
85
+ addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise<void>;
86
+ /**
87
+ * Should store the task and logs into the database, if any.
88
+ * If nothing to update, it should skip calling the internal store methods.
89
+ */
90
+ save(): Promise<void>;
91
+ }
92
+ export type ITaskManagerStore<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = Omit<ITaskManagerStorePrivate<T, O>, "save">;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=TaskManagerStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IResponseError,\n ITask,\n ITaskDataInput,\n ITaskLogItemData,\n ITaskResponseDoneResultOutput,\n ITaskUpdateData,\n TaskDataStatus\n} from \"~/types\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport type ITaskManagerStoreUpdateTaskValues<T = ITaskDataInput> = T;\n\nexport interface ITaskManagerStoreUpdateTaskValuesCb<T = ITaskDataInput> {\n (input: T): T;\n}\n\nexport interface ITaskManagerStoreUpdateTaskInputOptions {\n save: boolean;\n}\n\nexport type ITaskManagerStoreUpdateTaskInputParam<T = ITaskDataInput> =\n | ITaskManagerStoreUpdateTaskValuesCb<T>\n | Partial<ITaskManagerStoreUpdateTaskValues<T>>;\n\nexport interface ITaskManagerStoreUpdateTaskParamCb<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n (task: ITask<T, O>): ITaskUpdateData<T, O>;\n}\n\nexport type ITaskManagerStoreUpdateTask<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskUpdateData<T, O>;\n\nexport type ITaskManagerStoreUpdateTaskParams<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;\n\nexport interface ITaskManagerStoreInfoLog {\n message: string;\n data?: ITaskLogItemData;\n}\n\nexport interface ITaskManagerStoreErrorLog {\n message: string;\n data?: ITaskLogItemData;\n error: IResponseError | Error;\n}\n\nexport interface ITaskManagerStoreSetOutputOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreUpdateTaskOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreAddLogOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\n/**\n * Interface should not be used outside the @webiny/tasks package.\n */\nexport interface ITaskManagerStorePrivate<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n getTask: () => ITask<T, O>;\n getStatus: () => TaskDataStatus;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateTask(\n params: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void>;\n /**\n * List all child tasks of the current task.\n * If definitionId is provided, filter by that parameter.\n */\n listChildTasks<\n T = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n definitionId?: string\n ): Promise<ITask<T, O>[]>;\n /**\n * Update the task input, which are used to store custom user data.\n * You can send partial input, and it will be merged with the existing input.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateInput: (\n params: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ) => Promise<void>;\n getInput: () => T;\n /**\n * Update the task output, which are used to store the output data.\n * You can send partial output, and it will be merged with the existing output.\n *\n * Second parameter is optional options, and it contains a possibility not to store the task immediately.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateOutput: (\n values: Partial<O>,\n options?: ITaskManagerStoreSetOutputOptions\n ) => Promise<void>;\n getOutput: () => O;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise<void>;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n *\n *\n */\n addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise<void>;\n /**\n * Should store the task and logs into the database, if any.\n * If nothing to update, it should skip calling the internal store methods.\n */\n save(): Promise<void>;\n}\n\nexport type ITaskManagerStore<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = Omit<ITaskManagerStorePrivate<T, O>, \"save\">;\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ import type { Context } from "../../types";
2
+ import type { ITaskEvent } from "../../handler/types";
3
+ import type { IResponseResult } from "../../response/abstractions";
4
+ import type { ITimer } from "@webiny/handler-aws";
5
+ export interface IIsCloseToTimeoutCallable {
6
+ (seconds?: number): boolean;
7
+ }
8
+ export interface ITaskRunner<C extends Context = Context> {
9
+ context: C;
10
+ isCloseToTimeout: IIsCloseToTimeoutCallable;
11
+ timer: ITimer;
12
+ run(event: ITaskEvent): Promise<IResponseResult>;
13
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=TaskRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["TaskRunner.ts"],"sourcesContent":["import type { Context } from \"~/types\";\nimport type { ITaskEvent } from \"~/handler/types\";\nimport type { IResponseResult } from \"~/response/abstractions\";\nimport type { ITimer } from \"@webiny/handler-aws\";\n\nexport interface IIsCloseToTimeoutCallable {\n (seconds?: number): boolean;\n}\n\nexport interface ITaskRunner<C extends Context = Context> {\n context: C;\n isCloseToTimeout: IIsCloseToTimeoutCallable;\n timer: ITimer;\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export * from "./TaskControl";
2
+ export * from "./TaskEventValidation";
3
+ export * from "./TaskManager";
4
+ export * from "./TaskRunner";
5
+ export * from "./TaskManagerStore";
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _TaskControl = require("./TaskControl");
7
+ Object.keys(_TaskControl).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _TaskControl[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _TaskControl[key];
14
+ }
15
+ });
16
+ });
17
+ var _TaskEventValidation = require("./TaskEventValidation");
18
+ Object.keys(_TaskEventValidation).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _TaskEventValidation[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _TaskEventValidation[key];
25
+ }
26
+ });
27
+ });
28
+ var _TaskManager = require("./TaskManager");
29
+ Object.keys(_TaskManager).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _TaskManager[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _TaskManager[key];
36
+ }
37
+ });
38
+ });
39
+ var _TaskRunner = require("./TaskRunner");
40
+ Object.keys(_TaskRunner).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _TaskRunner[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _TaskRunner[key];
47
+ }
48
+ });
49
+ });
50
+ var _TaskManagerStore = require("./TaskManagerStore");
51
+ Object.keys(_TaskManagerStore).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _TaskManagerStore[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _TaskManagerStore[key];
58
+ }
59
+ });
60
+ });
61
+
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_TaskControl","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_TaskEventValidation","_TaskManager","_TaskRunner","_TaskManagerStore"],"sources":["index.ts"],"sourcesContent":["export * from \"./TaskControl\";\nexport * from \"./TaskEventValidation\";\nexport * from \"./TaskManager\";\nexport * from \"./TaskRunner\";\nexport * from \"./TaskManagerStore\";\n"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,oBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,oBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,oBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,oBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,YAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,YAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,YAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,YAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,WAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,WAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,WAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,WAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,iBAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,iBAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,iBAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,iBAAA,CAAAR,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export * from "./TaskRunner";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _TaskRunner = require("./TaskRunner");
7
+ Object.keys(_TaskRunner).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _TaskRunner[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _TaskRunner[key];
14
+ }
15
+ });
16
+ });
17
+
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_TaskRunner","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from \"./TaskRunner\";\n"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}