@webiny/api-headless-cms-bulk-actions 6.3.0 → 6.4.0-beta.0

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 (71) hide show
  1. package/abstractions/IUseCase.js +0 -3
  2. package/abstractions/index.js +0 -3
  3. package/domain/BulkActionName.js +9 -15
  4. package/domain/BulkActionName.js.map +1 -1
  5. package/features/BulkActionContext/abstractions.js +2 -3
  6. package/features/BulkActionContext/abstractions.js.map +1 -1
  7. package/features/BulkActionContext/index.js +0 -2
  8. package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js +22 -20
  9. package/features/DeleteEntriesBulkAction/DeleteEntriesBulkAction.js.map +1 -1
  10. package/features/DeleteEntriesBulkAction/feature.js +6 -5
  11. package/features/DeleteEntriesBulkAction/feature.js.map +1 -1
  12. package/features/EntriesBulkAction/abstractions.js +3 -2
  13. package/features/EntriesBulkAction/abstractions.js.map +1 -1
  14. package/features/EntriesBulkAction/createBulkActionTasks.js +114 -131
  15. package/features/EntriesBulkAction/createBulkActionTasks.js.map +1 -1
  16. package/features/EntriesBulkAction/internals/ChildTasksCleanup.js +27 -64
  17. package/features/EntriesBulkAction/internals/ChildTasksCleanup.js.map +1 -1
  18. package/features/EntriesBulkAction/internals/CreateTasksByModel.js +68 -99
  19. package/features/EntriesBulkAction/internals/CreateTasksByModel.js.map +1 -1
  20. package/features/EntriesBulkAction/internals/ProcessTask.js +35 -68
  21. package/features/EntriesBulkAction/internals/ProcessTask.js.map +1 -1
  22. package/features/EntriesBulkAction/internals/ProcessTaskResult.js +20 -19
  23. package/features/EntriesBulkAction/internals/ProcessTaskResult.js.map +1 -1
  24. package/features/EntriesBulkAction/internals/ProcessTasksByModel.js +37 -50
  25. package/features/EntriesBulkAction/internals/ProcessTasksByModel.js.map +1 -1
  26. package/features/EntriesBulkAction/internals/TaskCache.js +30 -64
  27. package/features/EntriesBulkAction/internals/TaskCache.js.map +1 -1
  28. package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js +20 -20
  29. package/features/MoveToFolderBulkAction/MoveToFolderBulkAction.js.map +1 -1
  30. package/features/MoveToFolderBulkAction/feature.js +6 -5
  31. package/features/MoveToFolderBulkAction/feature.js.map +1 -1
  32. package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js +22 -20
  33. package/features/MoveToTrashBulkAction/MoveToTrashBulkAction.js.map +1 -1
  34. package/features/MoveToTrashBulkAction/feature.js +6 -5
  35. package/features/MoveToTrashBulkAction/feature.js.map +1 -1
  36. package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js +27 -28
  37. package/features/PublishEntriesBulkAction/PublishEntriesBulkAction.js.map +1 -1
  38. package/features/PublishEntriesBulkAction/feature.js +6 -5
  39. package/features/PublishEntriesBulkAction/feature.js.map +1 -1
  40. package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js +20 -18
  41. package/features/RestoreEntriesBulkAction/RestoreEntriesBulkAction.js.map +1 -1
  42. package/features/RestoreEntriesBulkAction/feature.js +6 -5
  43. package/features/RestoreEntriesBulkAction/feature.js.map +1 -1
  44. package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js +20 -18
  45. package/features/UnpublishEntriesBulkAction/UnpublishEntriesBulkAction.js.map +1 -1
  46. package/features/UnpublishEntriesBulkAction/feature.js +6 -5
  47. package/features/UnpublishEntriesBulkAction/feature.js.map +1 -1
  48. package/graphql/createBulkActionGraphQL.js +44 -51
  49. package/graphql/createBulkActionGraphQL.js.map +1 -1
  50. package/graphql/createDefaultGraphQL.js +30 -34
  51. package/graphql/createDefaultGraphQL.js.map +1 -1
  52. package/handlers/eventBridgeEventHandler.js +23 -41
  53. package/handlers/eventBridgeEventHandler.js.map +1 -1
  54. package/handlers/index.js +5 -3
  55. package/handlers/index.js.map +1 -1
  56. package/handlers/setupEventsTenant.js +7 -9
  57. package/handlers/setupEventsTenant.js.map +1 -1
  58. package/index.js +29 -33
  59. package/index.js.map +1 -1
  60. package/package.json +17 -17
  61. package/tasks/EmptyTrashBinTaskDefinition.js +83 -109
  62. package/tasks/EmptyTrashBinTaskDefinition.js.map +1 -1
  63. package/tasks/createEmptyTrashBinsTask.js +4 -5
  64. package/tasks/createEmptyTrashBinsTask.js.map +1 -1
  65. package/tasks/index.js +0 -2
  66. package/types.js +7 -18
  67. package/types.js.map +1 -1
  68. package/abstractions/IUseCase.js.map +0 -1
  69. package/abstractions/index.js.map +0 -1
  70. package/features/BulkActionContext/index.js.map +0 -1
  71. package/tasks/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["TaskLogItemType","ChildTasksCleanup","execute","params","context","task","items","childTasks","tasks","listTasks","where","parentId","id","limit","length","childTaskIdList","map","childTask","childLogs","listLogs","task_in","deleteTasks","deletedChildTaskLogIdList","log","some","item","type","ERROR","deleteLog","includes","push","taskIds","taskId","deleteTask"],"sources":["ChildTasksCleanup.ts"],"sourcesContent":["import type { ITask, Context } from \"@webiny/tasks\";\nimport { TaskLogItemType } from \"@webiny/tasks\";\nimport type { IUseCase } from \"~/abstractions/index.js\";\nimport type { HcmsBulkActionsContext } from \"~/types.js\";\n\nexport interface IChildTasksCleanupExecuteParams {\n context: Context;\n task: ITask;\n}\n\n/**\n * Cleanup of the child tasks.\n * This code will remove all the child tasks and their logs, which have no errors in them.\n */\nexport class ChildTasksCleanup implements IUseCase<IChildTasksCleanupExecuteParams, void> {\n public async execute(params: IChildTasksCleanupExecuteParams): Promise<void> {\n const { context, task } = params;\n\n const { items: childTasks } = await context.tasks.listTasks({\n where: {\n parentId: task.id\n },\n // Really doubtful there will be more than 10k of child tasks.\n limit: 10000\n });\n\n if (childTasks.length === 0) {\n return;\n }\n\n const childTaskIdList = childTasks.map(childTask => childTask.id);\n\n const { items: childLogs } = await context.tasks.listLogs({\n where: {\n task_in: childTaskIdList\n },\n limit: 10000\n });\n\n /**\n * No logs found. Proceed with deleting the child tasks.\n */\n if (childLogs.length === 0) {\n await this.deleteTasks(context, childTaskIdList);\n }\n\n const deletedChildTaskLogIdList: string[] = [];\n /**\n * First, we need to remove all the logs which have no errors.\n */\n for (const log of childLogs) {\n if (log.items.some(item => item.type === TaskLogItemType.ERROR)) {\n continue;\n }\n await context.tasks.deleteLog(log.id);\n if (deletedChildTaskLogIdList.includes(log.task)) {\n continue;\n }\n deletedChildTaskLogIdList.push(log.task);\n }\n /**\n * Now we can remove the tasks.\n */\n await this.deleteTasks(context, deletedChildTaskLogIdList);\n }\n\n /**\n * Helper method to delete tasks by ID.\n */\n private async deleteTasks(context: HcmsBulkActionsContext, taskIds: string[]): Promise<void> {\n for (const taskId of taskIds) {\n await context.tasks.deleteTask(taskId);\n }\n }\n}\n"],"mappings":"AACA,SAASA,eAAe,QAAQ,eAAe;AAS/C;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,CAA4D;EACtF,MAAaC,OAAOA,CAACC,MAAuC,EAAiB;IACzE,MAAM;MAAEC,OAAO;MAAEC;IAAK,CAAC,GAAGF,MAAM;IAEhC,MAAM;MAAEG,KAAK,EAAEC;IAAW,CAAC,GAAG,MAAMH,OAAO,CAACI,KAAK,CAACC,SAAS,CAAC;MACxDC,KAAK,EAAE;QACHC,QAAQ,EAAEN,IAAI,CAACO;MACnB,CAAC;MACD;MACAC,KAAK,EAAE;IACX,CAAC,CAAC;IAEF,IAAIN,UAAU,CAACO,MAAM,KAAK,CAAC,EAAE;MACzB;IACJ;IAEA,MAAMC,eAAe,GAAGR,UAAU,CAACS,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACL,EAAE,CAAC;IAEjE,MAAM;MAAEN,KAAK,EAAEY;IAAU,CAAC,GAAG,MAAMd,OAAO,CAACI,KAAK,CAACW,QAAQ,CAAC;MACtDT,KAAK,EAAE;QACHU,OAAO,EAAEL;MACb,CAAC;MACDF,KAAK,EAAE;IACX,CAAC,CAAC;;IAEF;AACR;AACA;IACQ,IAAIK,SAAS,CAACJ,MAAM,KAAK,CAAC,EAAE;MACxB,MAAM,IAAI,CAACO,WAAW,CAACjB,OAAO,EAAEW,eAAe,CAAC;IACpD;IAEA,MAAMO,yBAAmC,GAAG,EAAE;IAC9C;AACR;AACA;IACQ,KAAK,MAAMC,GAAG,IAAIL,SAAS,EAAE;MACzB,IAAIK,GAAG,CAACjB,KAAK,CAACkB,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,IAAI,KAAK1B,eAAe,CAAC2B,KAAK,CAAC,EAAE;QAC7D;MACJ;MACA,MAAMvB,OAAO,CAACI,KAAK,CAACoB,SAAS,CAACL,GAAG,CAACX,EAAE,CAAC;MACrC,IAAIU,yBAAyB,CAACO,QAAQ,CAACN,GAAG,CAAClB,IAAI,CAAC,EAAE;QAC9C;MACJ;MACAiB,yBAAyB,CAACQ,IAAI,CAACP,GAAG,CAAClB,IAAI,CAAC;IAC5C;IACA;AACR;AACA;IACQ,MAAM,IAAI,CAACgB,WAAW,CAACjB,OAAO,EAAEkB,yBAAyB,CAAC;EAC9D;;EAEA;AACJ;AACA;EACI,MAAcD,WAAWA,CAACjB,OAA+B,EAAE2B,OAAiB,EAAiB;IACzF,KAAK,MAAMC,MAAM,IAAID,OAAO,EAAE;MAC1B,MAAM3B,OAAO,CAACI,KAAK,CAACyB,UAAU,CAACD,MAAM,CAAC;IAC1C;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"features/EntriesBulkAction/internals/ChildTasksCleanup.js","sources":["../../../../src/features/EntriesBulkAction/internals/ChildTasksCleanup.ts"],"sourcesContent":["import type { ITask, Context } from \"@webiny/tasks\";\nimport { TaskLogItemType } from \"@webiny/tasks\";\nimport type { IUseCase } from \"~/abstractions/index.js\";\nimport type { HcmsBulkActionsContext } from \"~/types.js\";\n\nexport interface IChildTasksCleanupExecuteParams {\n context: Context;\n task: ITask;\n}\n\n/**\n * Cleanup of the child tasks.\n * This code will remove all the child tasks and their logs, which have no errors in them.\n */\nexport class ChildTasksCleanup implements IUseCase<IChildTasksCleanupExecuteParams, void> {\n public async execute(params: IChildTasksCleanupExecuteParams): Promise<void> {\n const { context, task } = params;\n\n const { items: childTasks } = await context.tasks.listTasks({\n where: {\n parentId: task.id\n },\n // Really doubtful there will be more than 10k of child tasks.\n limit: 10000\n });\n\n if (childTasks.length === 0) {\n return;\n }\n\n const childTaskIdList = childTasks.map(childTask => childTask.id);\n\n const { items: childLogs } = await context.tasks.listLogs({\n where: {\n task_in: childTaskIdList\n },\n limit: 10000\n });\n\n /**\n * No logs found. Proceed with deleting the child tasks.\n */\n if (childLogs.length === 0) {\n await this.deleteTasks(context, childTaskIdList);\n }\n\n const deletedChildTaskLogIdList: string[] = [];\n /**\n * First, we need to remove all the logs which have no errors.\n */\n for (const log of childLogs) {\n if (log.items.some(item => item.type === TaskLogItemType.ERROR)) {\n continue;\n }\n await context.tasks.deleteLog(log.id);\n if (deletedChildTaskLogIdList.includes(log.task)) {\n continue;\n }\n deletedChildTaskLogIdList.push(log.task);\n }\n /**\n * Now we can remove the tasks.\n */\n await this.deleteTasks(context, deletedChildTaskLogIdList);\n }\n\n /**\n * Helper method to delete tasks by ID.\n */\n private async deleteTasks(context: HcmsBulkActionsContext, taskIds: string[]): Promise<void> {\n for (const taskId of taskIds) {\n await context.tasks.deleteTask(taskId);\n }\n }\n}\n"],"names":["ChildTasksCleanup","params","context","task","childTasks","childTaskIdList","childTask","childLogs","deletedChildTaskLogIdList","log","item","TaskLogItemType","taskIds","taskId"],"mappings":";AAcO,MAAMA;IACT,MAAa,QAAQC,MAAuC,EAAiB;QACzE,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGF;QAE1B,MAAM,EAAE,OAAOG,UAAU,EAAE,GAAG,MAAMF,QAAQ,KAAK,CAAC,SAAS,CAAC;YACxD,OAAO;gBACH,UAAUC,KAAK,EAAE;YACrB;YAEA,OAAO;QACX;QAEA,IAAIC,AAAsB,MAAtBA,WAAW,MAAM,EACjB;QAGJ,MAAMC,kBAAkBD,WAAW,GAAG,CAACE,CAAAA,YAAaA,UAAU,EAAE;QAEhE,MAAM,EAAE,OAAOC,SAAS,EAAE,GAAG,MAAML,QAAQ,KAAK,CAAC,QAAQ,CAAC;YACtD,OAAO;gBACH,SAASG;YACb;YACA,OAAO;QACX;QAKA,IAAIE,AAAqB,MAArBA,UAAU,MAAM,EAChB,MAAM,IAAI,CAAC,WAAW,CAACL,SAASG;QAGpC,MAAMG,4BAAsC,EAAE;QAI9C,KAAK,MAAMC,OAAOF,UACd,KAAIE,IAAI,KAAK,CAAC,IAAI,CAACC,CAAAA,OAAQA,KAAK,IAAI,KAAKC,gBAAgB,KAAK;YAG9D,MAAMT,QAAQ,KAAK,CAAC,SAAS,CAACO,IAAI,EAAE;YACpC,KAAID,0BAA0B,QAAQ,CAACC,IAAI,IAAI,GAG/CD,0BAA0B,IAAI,CAACC,IAAI,IAAI;;QAK3C,MAAM,IAAI,CAAC,WAAW,CAACP,SAASM;IACpC;IAKA,MAAc,YAAYN,OAA+B,EAAEU,OAAiB,EAAiB;QACzF,KAAK,MAAMC,UAAUD,QACjB,MAAMV,QAAQ,KAAK,CAAC,UAAU,CAACW;IAEvC;AACJ"}
@@ -1,107 +1,76 @@
1
1
  import { TaskCache } from "./TaskCache.js";
2
2
  import { BulkActionOperationByModelAction } from "../../../types.js";
3
3
  const MAX_TASK_LIST_LENGTH = 10;
4
-
5
- /**
6
- * The `CreateTasksByModel` class handles the execution of a task to process entries in batches.
7
- */
8
- export class CreateTasksByModel {
9
- constructor(context, getModel, bulkAction, taskDefinition, batchSize) {
10
- this.getModel = getModel;
11
- this.taskCache = new TaskCache(taskDefinition);
12
- this.batchSize = batchSize;
13
- this.bulkAction = bulkAction;
14
- this.context = context;
15
- }
16
- async execute(params) {
17
- const {
18
- input,
19
- controller
20
- } = params;
21
- try {
22
- const modelResult = await this.getModel.execute(input.modelId);
23
- if (modelResult.isFail()) {
24
- return controller.response.error(`Model with ${input.modelId} not found!`);
25
- }
26
- const model = modelResult.value;
27
- const listEntriesParams = {
28
- where: input.where,
29
- search: input.search,
30
- after: input.after,
31
- limit: this.batchSize
32
- };
33
- while (true) {
34
- if (controller.runtime.isAborted()) {
35
- return controller.response.aborted();
36
- } else if (controller.runtime.isCloseToTimeout()) {
37
- await this.taskCache.triggerTask(this.context, controller.state.getTask());
38
- return controller.response.continue({
39
- ...input,
40
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
41
- });
42
- }
43
-
44
- // List entries from the HCMS based on the provided query
45
- const {
46
- entries,
47
- meta
48
- } = await this.bulkAction.loadData(model, listEntriesParams);
49
-
50
- // End the task if no entries match the query
51
- if (meta.totalCount === 0) {
52
- return controller.response.continue({
53
- ...input,
54
- action: BulkActionOperationByModelAction.END_TASK
55
- });
56
- }
57
-
58
- // Continue processing if we are reached the task list length limit
59
- if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {
60
- await this.taskCache.triggerTask(this.context, controller.state.getTask());
61
- return controller.response.continue({
62
- ...input,
63
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
64
- });
65
- }
66
-
67
- // Continue processing if no entries are returned in the current batch
68
- if (entries.length === 0) {
69
- await this.taskCache.triggerTask(this.context, controller.state.getTask());
70
- return controller.response.continue({
71
- ...input,
72
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
73
- });
74
- }
75
-
76
- // Extract entry IDs
77
- const ids = [];
78
- for (let i = 0; i < entries.length; i++) {
79
- ids.push(entries[i].id);
80
- }
81
- if (ids.length > 0) {
82
- // Cache the task with the entry IDs
83
- this.taskCache.cacheTask({
84
- modelId: input.modelId,
85
- identity: input.identity,
86
- data: input.data,
87
- ids
88
- });
89
- }
90
-
91
- // Continue processing if there are no more entries or pagination is complete
92
- if (!meta.hasMoreItems || !meta.cursor) {
93
- await this.taskCache.triggerTask(this.context, controller.state.getTask());
94
- return controller.response.continue({
95
- ...input,
96
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
97
- });
4
+ class CreateTasksByModel {
5
+ constructor(context, getModel, bulkAction, taskDefinition, batchSize){
6
+ this.getModel = getModel;
7
+ this.taskCache = new TaskCache(taskDefinition);
8
+ this.batchSize = batchSize;
9
+ this.bulkAction = bulkAction;
10
+ this.context = context;
11
+ }
12
+ async execute(params) {
13
+ const { input, controller } = params;
14
+ try {
15
+ const modelResult = await this.getModel.execute(input.modelId);
16
+ if (modelResult.isFail()) return controller.response.error(`Model with ${input.modelId} not found!`);
17
+ const model = modelResult.value;
18
+ const listEntriesParams = {
19
+ where: input.where,
20
+ search: input.search,
21
+ after: input.after,
22
+ limit: this.batchSize
23
+ };
24
+ while(true){
25
+ if (controller.runtime.isAborted()) return controller.response.aborted();
26
+ if (controller.runtime.isCloseToTimeout()) {
27
+ await this.taskCache.triggerTask(this.context, controller.state.getTask());
28
+ return controller.response.continue({
29
+ ...input,
30
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
31
+ });
32
+ }
33
+ const { entries, meta } = await this.bulkAction.loadData(model, listEntriesParams);
34
+ if (0 === meta.totalCount) return controller.response.continue({
35
+ ...input,
36
+ action: BulkActionOperationByModelAction.END_TASK
37
+ });
38
+ if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {
39
+ await this.taskCache.triggerTask(this.context, controller.state.getTask());
40
+ return controller.response.continue({
41
+ ...input,
42
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
43
+ });
44
+ }
45
+ if (0 === entries.length) {
46
+ await this.taskCache.triggerTask(this.context, controller.state.getTask());
47
+ return controller.response.continue({
48
+ ...input,
49
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
50
+ });
51
+ }
52
+ const ids = [];
53
+ for(let i = 0; i < entries.length; i++)ids.push(entries[i].id);
54
+ if (ids.length > 0) this.taskCache.cacheTask({
55
+ modelId: input.modelId,
56
+ identity: input.identity,
57
+ data: input.data,
58
+ ids
59
+ });
60
+ if (!meta.hasMoreItems || !meta.cursor) {
61
+ await this.taskCache.triggerTask(this.context, controller.state.getTask());
62
+ return controller.response.continue({
63
+ ...input,
64
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
65
+ });
66
+ }
67
+ listEntriesParams.after = meta.cursor;
68
+ }
69
+ } catch (ex) {
70
+ return controller.response.error(ex.message ?? "Error while creating task.");
98
71
  }
99
- listEntriesParams.after = meta.cursor;
100
- }
101
- } catch (ex) {
102
- return controller.response.error(ex.message ?? `Error while creating task.`);
103
72
  }
104
- }
105
73
  }
74
+ export { CreateTasksByModel };
106
75
 
107
76
  //# sourceMappingURL=CreateTasksByModel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["TaskCache","BulkActionOperationByModelAction","MAX_TASK_LIST_LENGTH","CreateTasksByModel","constructor","context","getModel","bulkAction","taskDefinition","batchSize","taskCache","execute","params","input","controller","modelResult","modelId","isFail","response","error","model","value","listEntriesParams","where","search","after","limit","runtime","isAborted","aborted","isCloseToTimeout","triggerTask","state","getTask","continue","action","PROCESS_SUBTASKS","entries","meta","loadData","totalCount","END_TASK","getTasksLength","length","ids","i","push","id","cacheTask","identity","data","hasMoreItems","cursor","ex","message"],"sources":["CreateTasksByModel.ts"],"sourcesContent":["import type { CmsEntryListParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport { TaskCache } from \"./TaskCache.js\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionContext } from \"~/features/BulkActionContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nconst MAX_TASK_LIST_LENGTH = 10;\n\n/**\n * The `CreateTasksByModel` class handles the execution of a task to process entries in batches.\n */\nexport class CreateTasksByModel {\n private readonly taskCache: TaskCache;\n private readonly batchSize: number;\n private readonly bulkAction: EntriesBulkAction.Interface;\n private readonly context: BulkActionContext.Interface;\n private readonly getModel: GetModelUseCase.Interface;\n\n constructor(\n context: BulkActionContext.Interface,\n getModel: GetModelUseCase.Interface,\n bulkAction: EntriesBulkAction.Interface,\n taskDefinition: string,\n batchSize: number\n ) {\n this.getModel = getModel;\n this.taskCache = new TaskCache(taskDefinition);\n this.batchSize = batchSize;\n this.bulkAction = bulkAction;\n this.context = context;\n }\n\n async execute(params: IBulkActionOperationByModelTaskParams) {\n const { input, controller } = params;\n\n try {\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n const listEntriesParams: CmsEntryListParams = {\n where: input.where,\n search: input.search,\n after: input.after,\n limit: this.batchSize\n };\n\n while (true) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // List entries from the HCMS based on the provided query\n const { entries, meta } = await this.bulkAction.loadData(model, listEntriesParams);\n\n // End the task if no entries match the query\n if (meta.totalCount === 0) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.END_TASK\n });\n }\n\n // Continue processing if we are reached the task list length limit\n if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Continue processing if no entries are returned in the current batch\n if (entries.length === 0) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Extract entry IDs\n const ids: string[] = [];\n for (let i = 0; i < entries.length; i++) {\n ids.push(entries[i].id);\n }\n\n if (ids.length > 0) {\n // Cache the task with the entry IDs\n this.taskCache.cacheTask({\n modelId: input.modelId,\n identity: input.identity,\n data: input.data,\n ids\n });\n }\n\n // Continue processing if there are no more entries or pagination is complete\n if (!meta.hasMoreItems || !meta.cursor) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n listEntriesParams.after = meta.cursor;\n }\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while creating task.`);\n }\n }\n}\n"],"mappings":"AACA,SAASA,SAAS;AAElB,SAASC,gCAAgC;AAKzC,MAAMC,oBAAoB,GAAG,EAAE;;AAE/B;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAC;EAO5BC,WAAWA,CACPC,OAAoC,EACpCC,QAAmC,EACnCC,UAAuC,EACvCC,cAAsB,EACtBC,SAAiB,EACnB;IACE,IAAI,CAACH,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACI,SAAS,GAAG,IAAIV,SAAS,CAACQ,cAAc,CAAC;IAC9C,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACF,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACF,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMM,OAAOA,CAACC,MAA6C,EAAE;IACzD,MAAM;MAAEC,KAAK;MAAEC;IAAW,CAAC,GAAGF,MAAM;IAEpC,IAAI;MACA,MAAMG,WAAW,GAAG,MAAM,IAAI,CAACT,QAAQ,CAACK,OAAO,CAACE,KAAK,CAACG,OAAO,CAAC;MAE9D,IAAID,WAAW,CAACE,MAAM,CAAC,CAAC,EAAE;QACtB,OAAOH,UAAU,CAACI,QAAQ,CAACC,KAAK,CAAC,cAAcN,KAAK,CAACG,OAAO,aAAa,CAAC;MAC9E;MAEA,MAAMI,KAAK,GAAGL,WAAW,CAACM,KAAK;MAE/B,MAAMC,iBAAqC,GAAG;QAC1CC,KAAK,EAAEV,KAAK,CAACU,KAAK;QAClBC,MAAM,EAAEX,KAAK,CAACW,MAAM;QACpBC,KAAK,EAAEZ,KAAK,CAACY,KAAK;QAClBC,KAAK,EAAE,IAAI,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,OAAO,IAAI,4BAA4B,CAAC;IAChF;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"features/EntriesBulkAction/internals/CreateTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/CreateTasksByModel.ts"],"sourcesContent":["import type { CmsEntryListParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport { TaskCache } from \"./TaskCache.js\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { BulkActionContext } from \"~/features/BulkActionContext/index.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\n\nconst MAX_TASK_LIST_LENGTH = 10;\n\n/**\n * The `CreateTasksByModel` class handles the execution of a task to process entries in batches.\n */\nexport class CreateTasksByModel {\n private readonly taskCache: TaskCache;\n private readonly batchSize: number;\n private readonly bulkAction: EntriesBulkAction.Interface;\n private readonly context: BulkActionContext.Interface;\n private readonly getModel: GetModelUseCase.Interface;\n\n constructor(\n context: BulkActionContext.Interface,\n getModel: GetModelUseCase.Interface,\n bulkAction: EntriesBulkAction.Interface,\n taskDefinition: string,\n batchSize: number\n ) {\n this.getModel = getModel;\n this.taskCache = new TaskCache(taskDefinition);\n this.batchSize = batchSize;\n this.bulkAction = bulkAction;\n this.context = context;\n }\n\n async execute(params: IBulkActionOperationByModelTaskParams) {\n const { input, controller } = params;\n\n try {\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n const listEntriesParams: CmsEntryListParams = {\n where: input.where,\n search: input.search,\n after: input.after,\n limit: this.batchSize\n };\n\n while (true) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // List entries from the HCMS based on the provided query\n const { entries, meta } = await this.bulkAction.loadData(model, listEntriesParams);\n\n // End the task if no entries match the query\n if (meta.totalCount === 0) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.END_TASK\n });\n }\n\n // Continue processing if we are reached the task list length limit\n if (this.taskCache.getTasksLength() === MAX_TASK_LIST_LENGTH) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Continue processing if no entries are returned in the current batch\n if (entries.length === 0) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n // Extract entry IDs\n const ids: string[] = [];\n for (let i = 0; i < entries.length; i++) {\n ids.push(entries[i].id);\n }\n\n if (ids.length > 0) {\n // Cache the task with the entry IDs\n this.taskCache.cacheTask({\n modelId: input.modelId,\n identity: input.identity,\n data: input.data,\n ids\n });\n }\n\n // Continue processing if there are no more entries or pagination is complete\n if (!meta.hasMoreItems || !meta.cursor) {\n await this.taskCache.triggerTask(this.context, controller.state.getTask());\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n listEntriesParams.after = meta.cursor;\n }\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while creating task.`);\n }\n }\n}\n"],"names":["MAX_TASK_LIST_LENGTH","CreateTasksByModel","context","getModel","bulkAction","taskDefinition","batchSize","TaskCache","params","input","controller","modelResult","model","listEntriesParams","BulkActionOperationByModelAction","entries","meta","ids","i","ex"],"mappings":";;AAQA,MAAMA,uBAAuB;AAKtB,MAAMC;IAOT,YACIC,OAAoC,EACpCC,QAAmC,EACnCC,UAAuC,EACvCC,cAAsB,EACtBC,SAAiB,CACnB;QACE,IAAI,CAAC,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ACS,GAAG,OAAO,IAAI;QACnD;IACJ;AACJ"}
@@ -1,76 +1,43 @@
1
1
  import { ProcessTaskResult } from "./ProcessTaskResult.js";
2
- /**
3
- * The `ProcessTask` class is responsible for processing a batch of entries
4
- * based on the provided parameters. It uses a gateway to perform the actual
5
- * processing and maintains the results of the operations, including successfully
6
- * processed and failed entries.
7
- */
8
- export class ProcessTask {
9
- constructor(bulkAction, getModel) {
10
- this.bulkAction = bulkAction;
11
- this.getModel = getModel;
12
- this.result = new ProcessTaskResult();
13
- }
14
- async execute({
15
- input,
16
- controller
17
- }) {
18
- try {
19
- if (controller.runtime.isAborted()) {
20
- return controller.response.aborted();
21
- } else if (controller.runtime.isCloseToTimeout()) {
22
- return controller.response.continue({
23
- ...input
24
- });
25
- }
26
-
27
- // Check if the input contains a model ID.
28
- if (!input.modelId) {
29
- return controller.response.error(`Missing "modelId" in the input.`);
30
- }
31
-
32
- // Check if the model exists.
33
- const modelResult = await this.getModel.execute(input.modelId);
34
- if (modelResult.isFail()) {
35
- return controller.response.error(`Model with ${input.modelId} not found!`);
36
- }
37
- const model = modelResult.value;
38
-
39
- // Check if there are any IDs to process.
40
- if (!input.ids || input.ids.length === 0) {
41
- return controller.response.done(`Task done: no entries to process for "${input.modelId}" model.`, {
42
- done: [],
43
- failed: []
44
- });
45
- }
46
-
47
- // Process each ID in the input.
48
- for (const id of input.ids) {
2
+ class ProcessTask {
3
+ constructor(bulkAction, getModel){
4
+ this.bulkAction = bulkAction;
5
+ this.getModel = getModel;
6
+ this.result = new ProcessTaskResult();
7
+ }
8
+ async execute({ input, controller }) {
49
9
  try {
50
- // Execute the gateway operation for the current ID.
51
- await this.bulkAction.processData(model, {
52
- id,
53
- data: input.data
54
- });
55
-
56
- // Add the ID to the list of successfully processed entries.
57
- this.result.addDone(id);
10
+ if (controller.runtime.isAborted()) return controller.response.aborted();
11
+ if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
12
+ ...input
13
+ });
14
+ if (!input.modelId) return controller.response.error('Missing "modelId" in the input.');
15
+ const modelResult = await this.getModel.execute(input.modelId);
16
+ if (modelResult.isFail()) return controller.response.error(`Model with ${input.modelId} not found!`);
17
+ const model = modelResult.value;
18
+ if (!input.ids || 0 === input.ids.length) return controller.response.done(`Task done: no entries to process for "${input.modelId}" model.`, {
19
+ done: [],
20
+ failed: []
21
+ });
22
+ for (const id of input.ids)try {
23
+ await this.bulkAction.processData(model, {
24
+ id,
25
+ data: input.data
26
+ });
27
+ this.result.addDone(id);
28
+ } catch (ex) {
29
+ console.error(ex.message || `Failed to process entry with id "${id}".`);
30
+ this.result.addFailed(id);
31
+ }
32
+ return controller.response.done(`Task done: all entries processed for "${model.name}" model.`, {
33
+ done: this.result.getDone(),
34
+ failed: this.result.getFailed()
35
+ });
58
36
  } catch (ex) {
59
- console.error(ex.message || `Failed to process entry with id "${id}".`);
60
- // Add the ID to the list of failed entries.
61
- this.result.addFailed(id);
37
+ return controller.response.error(ex.message ?? "Error while processing task.");
62
38
  }
63
- }
64
-
65
- // Return a done response with the results of the processing.
66
- return controller.response.done(`Task done: all entries processed for "${model.name}" model.`, {
67
- done: this.result.getDone(),
68
- failed: this.result.getFailed()
69
- });
70
- } catch (ex) {
71
- return controller.response.error(ex.message ?? `Error while processing task.`);
72
39
  }
73
- }
74
40
  }
41
+ export { ProcessTask };
75
42
 
76
43
  //# sourceMappingURL=ProcessTask.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ProcessTaskResult","ProcessTask","constructor","bulkAction","getModel","result","execute","input","controller","runtime","isAborted","response","aborted","isCloseToTimeout","continue","modelId","error","modelResult","isFail","model","value","ids","length","done","failed","id","processData","data","addDone","ex","console","message","addFailed","name","getDone","getFailed"],"sources":["ProcessTask.ts"],"sourcesContent":["import { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { ProcessTaskResult } from \"./ProcessTaskResult.js\";\nimport type { IBulkActionOperationTaskParams } from \"~/types.js\";\n\n/**\n * The `ProcessTask` class is responsible for processing a batch of entries\n * based on the provided parameters. It uses a gateway to perform the actual\n * processing and maintains the results of the operations, including successfully\n * processed and failed entries.\n */\nexport class ProcessTask {\n private readonly result: ProcessTaskResult;\n\n constructor(\n private bulkAction: EntriesBulkAction.Interface,\n private getModel: GetModelUseCase.Interface\n ) {\n this.result = new ProcessTaskResult();\n }\n\n async execute({ input, controller }: IBulkActionOperationTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input\n });\n }\n\n // Check if the input contains a model ID.\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n\n // Check if the model exists.\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n // Check if there are any IDs to process.\n if (!input.ids || input.ids.length === 0) {\n return controller.response.done(\n `Task done: no entries to process for \"${input.modelId}\" model.`,\n {\n done: [],\n failed: []\n }\n );\n }\n\n // Process each ID in the input.\n for (const id of input.ids) {\n try {\n // Execute the gateway operation for the current ID.\n await this.bulkAction.processData(model, {\n id,\n data: input.data\n });\n\n // Add the ID to the list of successfully processed entries.\n this.result.addDone(id);\n } catch (ex) {\n console.error(ex.message || `Failed to process entry with id \"${id}\".`);\n // Add the ID to the list of failed entries.\n this.result.addFailed(id);\n }\n }\n\n // Return a done response with the results of the processing.\n return controller.response.done(\n `Task done: all entries processed for \"${model.name}\" model.`,\n {\n done: this.result.getDone(),\n failed: this.result.getFailed()\n }\n );\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while processing task.`);\n }\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAG1B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,CAAC;EAGrBC,WAAWA,CACCC,UAAuC,EACvCC,QA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G,EAAE;QACxB,IAAI;UACA;UACA,MAAM,IAAI,CAAClB,UAAU,CAACuB,WAAW,CAACP,KAAK,EAAE;YACrCM,EAAE;YACFE,IAAI,EAAEpB,KAAK,CAACoB;UAChB,CAAC,CAAC;;UAEF;UACA,IAAI,CAACtB,MAAM,CAACuB,OAAO,CAACH,EAAE,CAAC;QAC3B,CAAC,CAAC,OAAOI,EAAE,EAAE;UACTC,OAAO,CAACd,KAAK,CAACa,EAAE,CAACE,OAAO,IAAI,oCAAoCN,EAAE,IAAI,CAAC;UACvE;UACA,IAAI,CAACpB,MAAM,CAAC2B,SAAS,CAACP,EAAE,CAAC;QAC7B;MACJ;;MAEA;MACA,OAAOjB,UAAU,CAACG,QAAQ,CAACY,IAAI,CAC3B,yCAAyCJ,KAAK,CAACc,IAAI,UAAU,EAC7D;QACIV,IAAI,EAAE,IAAI,CAAClB,MAAM,CAAC6B,OAAO,CAAC,CAAC;QAC3BV,MAAM,EAAE,IAAI,CAACnB,MAAM,CAAC8B,SAAS,CAAC;MAClC,CACJ,CAAC;IACL,CAAC,CAAC,OAAON,EAAE,EAAE;MACT,OAAOrB,UAAU,CAACG,QAAQ,CAACK,KAAK,CAACa,EAAE,CAACE,OAAO,IAAI,8BAA8B,CAAC;IAClF;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"features/EntriesBulkAction/internals/ProcessTask.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTask.ts"],"sourcesContent":["import { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { EntriesBulkAction } from \"~/features/EntriesBulkAction/abstractions.js\";\nimport { ProcessTaskResult } from \"./ProcessTaskResult.js\";\nimport type { IBulkActionOperationTaskParams } from \"~/types.js\";\n\n/**\n * The `ProcessTask` class is responsible for processing a batch of entries\n * based on the provided parameters. It uses a gateway to perform the actual\n * processing and maintains the results of the operations, including successfully\n * processed and failed entries.\n */\nexport class ProcessTask {\n private readonly result: ProcessTaskResult;\n\n constructor(\n private bulkAction: EntriesBulkAction.Interface,\n private getModel: GetModelUseCase.Interface\n ) {\n this.result = new ProcessTaskResult();\n }\n\n async execute({ input, controller }: IBulkActionOperationTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input\n });\n }\n\n // Check if the input contains a model ID.\n if (!input.modelId) {\n return controller.response.error(`Missing \"modelId\" in the input.`);\n }\n\n // Check if the model exists.\n const modelResult = await this.getModel.execute(input.modelId);\n\n if (modelResult.isFail()) {\n return controller.response.error(`Model with ${input.modelId} not found!`);\n }\n\n const model = modelResult.value;\n\n // Check if there are any IDs to process.\n if (!input.ids || input.ids.length === 0) {\n return controller.response.done(\n `Task done: no entries to process for \"${input.modelId}\" model.`,\n {\n done: [],\n failed: []\n }\n );\n }\n\n // Process each ID in the input.\n for (const id of input.ids) {\n try {\n // Execute the gateway operation for the current ID.\n await this.bulkAction.processData(model, {\n id,\n data: input.data\n });\n\n // Add the ID to the list of successfully processed entries.\n this.result.addDone(id);\n } catch (ex) {\n console.error(ex.message || `Failed to process entry with id \"${id}\".`);\n // Add the ID to the list of failed entries.\n this.result.addFailed(id);\n }\n }\n\n // Return a done response with the results of the processing.\n return controller.response.done(\n `Task done: all entries processed for \"${model.name}\" model.`,\n {\n done: this.result.getDone(),\n failed: this.result.getFailed()\n }\n );\n } catch (ex) {\n return controller.response.error(ex.message ?? `Error while processing task.`);\n }\n }\n}\n"],"names":["ProcessTask","bulkAction","getModel","ProcessTaskResult","input","controller","modelResult","model","id","ex","console"],"mappings":";AAWO,MAAMA;IAGT,YACYC,UAAuC,EACvCC,QAAmC,CAC7C;aAFUD,UAAU,GAAVA;aACAC,QAAQ,GAARA;QAER,IAAI,CAAC,MAAM,GAAG,IAAIC;IACtB;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAkC,EAAE;QACjE,IAAI;YACA,IAAIA,WAAW,OAAO,CAA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AS;YACjC;QAER,EAAE,OAAOE,IAAI;YACT,OAAOJ,WAAW,QAAQ,CAAC,KAAK,CAACI,GAAG,OAAO,IAAI;QACnD;IACJ;AACJ"}
@@ -1,22 +1,23 @@
1
- export class ProcessTaskResult {
2
- constructor() {
3
- this.done = new Set();
4
- this.failed = new Set();
5
- }
6
- addDone(entryId) {
7
- this.failed.delete(entryId);
8
- this.done.add(entryId);
9
- }
10
- addFailed(entryId) {
11
- this.failed.add(entryId);
12
- this.done.delete(entryId);
13
- }
14
- getFailed() {
15
- return Array.from(this.failed);
16
- }
17
- getDone() {
18
- return Array.from(this.done);
19
- }
1
+ class ProcessTaskResult {
2
+ constructor(){
3
+ this.done = new Set();
4
+ this.failed = new Set();
5
+ }
6
+ addDone(entryId) {
7
+ this.failed.delete(entryId);
8
+ this.done.add(entryId);
9
+ }
10
+ addFailed(entryId) {
11
+ this.failed.add(entryId);
12
+ this.done.delete(entryId);
13
+ }
14
+ getFailed() {
15
+ return Array.from(this.failed);
16
+ }
17
+ getDone() {
18
+ return Array.from(this.done);
19
+ }
20
20
  }
21
+ export { ProcessTaskResult };
21
22
 
22
23
  //# sourceMappingURL=ProcessTaskResult.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ProcessTaskResult","constructor","done","Set","failed","addDone","entryId","delete","add","addFailed","getFailed","Array","from","getDone"],"sources":["ProcessTaskResult.ts"],"sourcesContent":["export class ProcessTaskResult {\n private readonly done: Set<string>;\n private readonly failed: Set<string>;\n\n public constructor() {\n this.done = new Set();\n this.failed = new Set();\n }\n\n public addDone(entryId: string): void {\n this.failed.delete(entryId);\n this.done.add(entryId);\n }\n\n public addFailed(entryId: string): void {\n this.failed.add(entryId);\n this.done.delete(entryId);\n }\n\n public getFailed() {\n return Array.from(this.failed);\n }\n\n public getDone() {\n return Array.from(this.done);\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,CAAC;EAIpBC,WAAWA,CAAA,EAAG;IACjB,IAAI,CAACC,IAAI,GAAG,IAAIC,GAAG,CAAC,CAAC;IACrB,IAAI,CAACC,MAAM,GAAG,IAAID,GAAG,CAAC,CAAC;EAC3B;EAEOE,OAAOA,CAACC,OAAe,EAAQ;IAClC,IAAI,CAACF,MAAM,CAACG,MAAM,CAACD,OAAO,CAAC;IAC3B,IAAI,CAACJ,IAAI,CAACM,GAAG,CAACF,OAAO,CAAC;EAC1B;EAEOG,SAASA,CAACH,OAAe,EAAQ;IACpC,IAAI,CAACF,MAAM,CAACI,GAAG,CAACF,OAAO,CAAC;IACxB,IAAI,CAACJ,IAAI,CAACK,MAAM,CAACD,OAAO,CAAC;EAC7B;EAEOI,SAASA,CAAA,EAAG;IACf,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACR,MAAM,CAAC;EAClC;EAEOS,OAAOA,CAAA,EAAG;IACb,OAAOF,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,IAAI,CAAC;EAChC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"features/EntriesBulkAction/internals/ProcessTaskResult.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTaskResult.ts"],"sourcesContent":["export class ProcessTaskResult {\n private readonly done: Set<string>;\n private readonly failed: Set<string>;\n\n public constructor() {\n this.done = new Set();\n this.failed = new Set();\n }\n\n public addDone(entryId: string): void {\n this.failed.delete(entryId);\n this.done.add(entryId);\n }\n\n public addFailed(entryId: string): void {\n this.failed.add(entryId);\n this.done.delete(entryId);\n }\n\n public getFailed() {\n return Array.from(this.failed);\n }\n\n public getDone() {\n return Array.from(this.done);\n }\n}\n"],"names":["ProcessTaskResult","Set","entryId","Array"],"mappings":"AAAO,MAAMA;IAIT,aAAqB;QACjB,IAAI,CAAC,IAAI,GAAG,IAAIC;QAChB,IAAI,CAAC,MAAM,GAAG,IAAIA;IACtB;IAEO,QAAQC,OAAe,EAAQ;QAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA;QACnB,IAAI,CAAC,IAAI,CAAC,GAAG,CAACA;IAClB;IAEO,UAAUA,OAAe,EAAQ;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;QAChB,IAAI,CAAC,IAAI,CAAC,MAAM,CAACA;IACrB;IAEO,YAAY;QACf,OAAOC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEO,UAAU;QACb,OAAOA,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI;IAC/B;AACJ"}
@@ -1,56 +1,43 @@
1
1
  import { TaskDataStatus } from "@webiny/tasks";
2
2
  import { BulkActionOperationByModelAction } from "../../../types.js";
3
- /**
4
- * The `ProcessTasksByModel` class is responsible for processing tasks for a specific model.
5
- * It checks for any running or pending tasks from the parent task and continues or completes
6
- * the task based on the status.
7
- */
8
- export class ProcessTasksByModel {
9
- constructor(context, taskDefinition) {
10
- this.context = context;
11
- this.taskDefinition = taskDefinition;
12
- }
13
- async execute({
14
- input,
15
- controller
16
- }) {
17
- try {
18
- if (controller.runtime.isAborted()) {
19
- return controller.response.aborted();
20
- } else if (controller.runtime.isCloseToTimeout()) {
21
- return controller.response.continue({
22
- ...input,
23
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
24
- });
25
- }
26
- const {
27
- items
28
- } = await this.context.tasks.listTasks({
29
- where: {
30
- parentId: controller.state.getTask().id,
31
- definitionId: this.taskDefinition,
32
- taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]
33
- },
34
- limit: 1
35
- });
36
-
37
- // If there are running or pending tasks, continue with a wait.
38
- if (items.length > 0) {
39
- return controller.response.continue({
40
- ...input,
41
- action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
42
- }, {
43
- seconds: 120
44
- });
45
- }
46
- return controller.response.continue({
47
- ...input,
48
- action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS
49
- });
50
- } catch (ex) {
51
- return controller.response.error(ex.message ?? `Error while processing task "${this.taskDefinition}"`);
3
+ class ProcessTasksByModel {
4
+ constructor(context, taskDefinition){
5
+ this.context = context;
6
+ this.taskDefinition = taskDefinition;
7
+ }
8
+ async execute({ input, controller }) {
9
+ try {
10
+ if (controller.runtime.isAborted()) return controller.response.aborted();
11
+ if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
12
+ ...input,
13
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
14
+ });
15
+ const { items } = await this.context.tasks.listTasks({
16
+ where: {
17
+ parentId: controller.state.getTask().id,
18
+ definitionId: this.taskDefinition,
19
+ taskStatus_in: [
20
+ TaskDataStatus.RUNNING,
21
+ TaskDataStatus.PENDING
22
+ ]
23
+ },
24
+ limit: 1
25
+ });
26
+ if (items.length > 0) return controller.response.continue({
27
+ ...input,
28
+ action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
29
+ }, {
30
+ seconds: 120
31
+ });
32
+ return controller.response.continue({
33
+ ...input,
34
+ action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS
35
+ });
36
+ } catch (ex) {
37
+ return controller.response.error(ex.message ?? `Error while processing task "${this.taskDefinition}"`);
38
+ }
52
39
  }
53
- }
54
40
  }
41
+ export { ProcessTasksByModel };
55
42
 
56
43
  //# sourceMappingURL=ProcessTasksByModel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["TaskDataStatus","BulkActionOperationByModelAction","ProcessTasksByModel","constructor","context","taskDefinition","execute","input","controller","runtime","isAborted","response","aborted","isCloseToTimeout","continue","action","PROCESS_SUBTASKS","items","tasks","listTasks","where","parentId","state","getTask","id","definitionId","taskStatus_in","RUNNING","PENDING","limit","length","seconds","CHECK_MORE_SUBTASKS","ex","error","message"],"sources":["ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/tasks\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { BulkActionContext } from \"~/features/BulkActionContext/index.js\";\n\n/**\n * The `ProcessTasksByModel` class is responsible for processing tasks for a specific model.\n * It checks for any running or pending tasks from the parent task and continues or completes\n * the task based on the status.\n */\nexport class ProcessTasksByModel {\n private context: BulkActionContext.Interface;\n private readonly taskDefinition: string;\n\n constructor(context: BulkActionContext.Interface, taskDefinition: string) {\n this.context = context;\n this.taskDefinition = taskDefinition;\n }\n\n async execute({ input, controller }: IBulkActionOperationByModelTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n const { items } = await this.context.tasks.listTasks({\n where: {\n parentId: controller.state.getTask().id,\n definitionId: this.taskDefinition,\n taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]\n },\n limit: 1\n });\n\n // If there are running or pending tasks, continue with a wait.\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n },\n {\n seconds: 120\n }\n );\n }\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS\n });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? `Error while processing task \"${this.taskDefinition}\"`\n );\n }\n }\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,eAAe;AAE9C,SAASC,gCAAgC;AAGzC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,CAAC;EAI7BC,WAAWA,CAACC,OAAoC,EAAEC,cAAsB,EAAE;IACtE,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,cAAc,GAAGA,cAAc;EACxC;EAEA,MAAMC,OAAOA,CAAC;IAAEC,KAAK;IAAEC;EAAkD,CAAC,EAAE;IACxE,IAAI;MACA,IAAIA,UAAU,CAACC,OAAO,CAACC,SAAS,CAAC,CAAC,EAAE;QAChC,OAAOF,UAAU,CAACG,QAAQ,CAACC,OAAO,CAAC,CAAC;MACxC,CAAC,MAAM,IAAIJ,UAAU,CAACC,OAAO,CAACI,gBAAgB,CAAC,CAAC,EAAE;QAC9C,OAAOL,UAAU,CAACG,QAAQ,CAACG,QAAQ,CAAC;UAChC,GAAGP,KAAK;UACRQ,MAAM,EAAEd,gCAAgC,CAACe;QAC7C,CAAC,CAAC;MACN;MAEA,MAAM;QAAEC;MAAM,CAAC,GAAG,MAAM,IAAI,CAACb,OAAO,CAACc,KAAK,CAACC,SAAS,CAAC;QACjDC,KAAK,EAAE;UACHC,QAAQ,EAAEb,UAAU,CAACc,KAAK,CAACC,OAAO,CAAC,CAAC,CAACC,EAAE;UACvCC,YAAY,EAAE,IAAI,CAACpB,cAAc;UACjCqB,aAAa,EAAE,CAAC1B,cAAc,CAAC2B,OAAO,EAAE3B,cAAc,CAAC4B,OAAO;QAClE,CAAC;QACDC,KAAK,EAAE;MACX,CAAC,CAAC;;MAEF;MACA,IAAIZ,KAAK,CAACa,MAAM,GAAG,CAAC,EAAE;QAClB,OAAOtB,UAAU,CAACG,QAAQ,CAACG,QAAQ,CAC/B;UACI,GAAGP,KAAK;UACRQ,MAAM,EAAEd,gCAAgC,CAACe;QAC7C,CAAC,EACD;UACIe,OAAO,EAAE;QACb,CACJ,CAAC;MACL;MAEA,OAAOvB,UAAU,CAACG,QAAQ,CAACG,QAAQ,CAAC;QAChC,GAAGP,KAAK;QACRQ,MAAM,EAAEd,gCAAgC,CAAC+B;MAC7C,CAAC,CAAC;IACN,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,OAAOzB,UAAU,CAACG,QAAQ,CAACuB,KAAK,CAC5BD,EAAE,CAACE,OAAO,IAAI,gCAAgC,IAAI,CAAC9B,cAAc,GACrE,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"features/EntriesBulkAction/internals/ProcessTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/tasks\";\nimport type { IBulkActionOperationByModelTaskParams } from \"~/types.js\";\nimport { BulkActionOperationByModelAction } from \"~/types.js\";\nimport { BulkActionContext } from \"~/features/BulkActionContext/index.js\";\n\n/**\n * The `ProcessTasksByModel` class is responsible for processing tasks for a specific model.\n * It checks for any running or pending tasks from the parent task and continues or completes\n * the task based on the status.\n */\nexport class ProcessTasksByModel {\n private context: BulkActionContext.Interface;\n private readonly taskDefinition: string;\n\n constructor(context: BulkActionContext.Interface, taskDefinition: string) {\n this.context = context;\n this.taskDefinition = taskDefinition;\n }\n\n async execute({ input, controller }: IBulkActionOperationByModelTaskParams) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n } else if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n });\n }\n\n const { items } = await this.context.tasks.listTasks({\n where: {\n parentId: controller.state.getTask().id,\n definitionId: this.taskDefinition,\n taskStatus_in: [TaskDataStatus.RUNNING, TaskDataStatus.PENDING]\n },\n limit: 1\n });\n\n // If there are running or pending tasks, continue with a wait.\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input,\n action: BulkActionOperationByModelAction.PROCESS_SUBTASKS\n },\n {\n seconds: 120\n }\n );\n }\n\n return controller.response.continue({\n ...input,\n action: BulkActionOperationByModelAction.CHECK_MORE_SUBTASKS\n });\n } catch (ex) {\n return controller.response.error(\n ex.message ?? `Error while processing task \"${this.taskDefinition}\"`\n );\n }\n }\n}\n"],"names":["ProcessTasksByModel","context","taskDefinition","input","controller","BulkActionOperationByModelAction","items","TaskDataStatus","ex"],"mappings":";;AAUO,MAAMA;IAIT,YAAYC,OAAoC,EAAEC,cAAsB,CAAE;QACtE,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQ,EAAEC,KAAK,EAAEC,UAAU,EAAyC,EAAE;QACxE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;YAC/B,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IAC1C,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,gBAAgB;YAC7D;YAGJ,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;gBACjD,OAAO;oBACH,UAAUF,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;oBACvC,cAAc,IAAI,CAAC,cAAc;oBACjC,eAAe;wBAACG,eAAe,OAAO;wBAAEA,eAAe,OAAO;qBAAC;gBACnE;gBACA,OAAO;YACX;YAGA,IAAID,MAAM,MAAM,GAAG,GACf,OAAOF,WAAW,QAAQ,CAAC,QAAQ,CAC/B;gBACI,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,gBAAgB;YAC7D,GACA;gBACI,SAAS;YACb;YAIR,OAAOD,WAAW,QAAQ,CAAC,QAAQ,CAAC;gBAChC,GAAGD,KAAK;gBACR,QAAQE,iCAAiC,mBAAmB;YAChE;QACJ,EAAE,OAAOG,IAAI;YACT,OAAOJ,WAAW,QAAQ,CAAC,KAAK,CAC5BI,GAAG,OAAO,IAAI,CAAC,6BAA6B,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;QAE5E;IACJ;AACJ"}