@webiny/api-headless-cms-bulk-actions 6.4.11 → 6.4.12-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js +1 -1
- package/features/EntriesBulkAction/internals/CreateTasksByModel.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTask.js +1 -1
- package/features/EntriesBulkAction/internals/ProcessTask.js.map +1 -1
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js +1 -1
- package/features/EntriesBulkAction/internals/ProcessTasksByModel.js.map +1 -1
- package/package.json +15 -15
|
@@ -23,7 +23,7 @@ class CreateTasksByModel {
|
|
|
23
23
|
};
|
|
24
24
|
while(true){
|
|
25
25
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
26
|
-
if (controller.runtime.isCloseToTimeout()) {
|
|
26
|
+
else if (controller.runtime.isCloseToTimeout()) {
|
|
27
27
|
await this.taskCache.triggerTask(this.context, controller.state.getTask());
|
|
28
28
|
return controller.response.continue({
|
|
29
29
|
...input,
|
|
@@ -1 +1 @@
|
|
|
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,QAAQ,GAAGH;QAChB,IAAI,CAAC,SAAS,GAAG,IAAII,UAAUF;QAC/B,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,OAAO,GAAGF;IACnB;IAEA,MAAM,QAAQM,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,IAAI;YACA,MAAMG,cAAc,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACF,MAAM,OAAO;YAE7D,IAAIE,YAAY,MAAM,IAClB,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAED,MAAM,OAAO,CAAC,WAAW,CAAC;YAG7E,MAAMG,QAAQD,YAAY,KAAK;YAE/B,MAAME,oBAAwC;gBAC1C,OAAOJ,MAAM,KAAK;gBAClB,QAAQA,MAAM,MAAM;gBACpB,OAAOA,MAAM,KAAK;gBAClB,OAAO,IAAI,CAAC,SAAS;YACzB;YAEA,MAAO,KAAM;gBACT,IAAIC,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;
|
|
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,O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GG,KAAK,MAAM;YACzC;QACJ,EAAE,OAAOG,IAAI;YACT,OAAOT,WAAW,QAAQ,CAAC,KAAK,CAACS,GAAG,OAAO,IAAI;QACnD;IACJ;AACJ"}
|
|
@@ -8,7 +8,7 @@ class ProcessTask {
|
|
|
8
8
|
async execute({ input, controller }) {
|
|
9
9
|
try {
|
|
10
10
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
11
|
-
if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
11
|
+
else if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
12
12
|
...input
|
|
13
13
|
});
|
|
14
14
|
if (!input.modelId) return controller.response.error('Missing "modelId" in the input.');
|
|
@@ -1 +1 @@
|
|
|
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,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;
|
|
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,IAA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AsC,EAAEE,MAAM,IAAI,CAAC,QAAQ,CAAC,EAC7D;gBACI,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO;gBACzB,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS;YACjC;QAER,EAAE,OAAOE,IAAI;YACT,OAAOJ,WAAW,QAAQ,CAAC,KAAK,CAACI,GAAG,OAAO,IAAI;QACnD;IACJ;AACJ"}
|
|
@@ -8,7 +8,7 @@ class ProcessTasksByModel {
|
|
|
8
8
|
async execute({ input, controller }) {
|
|
9
9
|
try {
|
|
10
10
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
11
|
-
if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
11
|
+
else if (controller.runtime.isCloseToTimeout()) return controller.response.continue({
|
|
12
12
|
...input,
|
|
13
13
|
action: BulkActionOperationByModelAction.PROCESS_SUBTASKS
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/background-tasks/api\";\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;
|
|
1
|
+
{"version":3,"file":"features/EntriesBulkAction/internals/ProcessTasksByModel.js","sources":["../../../../src/features/EntriesBulkAction/internals/ProcessTasksByModel.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/background-tasks/api\";\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;iBAC/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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-bulk-actions",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.12-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,24 +17,24 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api-headless-cms": "6.4.
|
|
21
|
-
"@webiny/background-tasks": "6.4.
|
|
22
|
-
"@webiny/feature": "6.4.
|
|
23
|
-
"@webiny/handler": "6.4.
|
|
24
|
-
"@webiny/handler-aws": "6.4.
|
|
25
|
-
"@webiny/utils": "6.4.
|
|
20
|
+
"@webiny/api-headless-cms": "6.4.12-beta.1",
|
|
21
|
+
"@webiny/background-tasks": "6.4.12-beta.1",
|
|
22
|
+
"@webiny/feature": "6.4.12-beta.1",
|
|
23
|
+
"@webiny/handler": "6.4.12-beta.1",
|
|
24
|
+
"@webiny/handler-aws": "6.4.12-beta.1",
|
|
25
|
+
"@webiny/utils": "6.4.12-beta.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@webiny/api": "6.4.
|
|
29
|
-
"@webiny/api-core": "6.4.
|
|
30
|
-
"@webiny/build-tools": "6.4.
|
|
31
|
-
"@webiny/handler-graphql": "6.4.
|
|
32
|
-
"@webiny/plugins": "6.4.
|
|
33
|
-
"@webiny/project-utils": "6.4.
|
|
34
|
-
"@webiny/wcp": "6.4.
|
|
28
|
+
"@webiny/api": "6.4.12-beta.1",
|
|
29
|
+
"@webiny/api-core": "6.4.12-beta.1",
|
|
30
|
+
"@webiny/build-tools": "6.4.12-beta.1",
|
|
31
|
+
"@webiny/handler-graphql": "6.4.12-beta.1",
|
|
32
|
+
"@webiny/plugins": "6.4.12-beta.1",
|
|
33
|
+
"@webiny/project-utils": "6.4.12-beta.1",
|
|
34
|
+
"@webiny/wcp": "6.4.12-beta.1",
|
|
35
35
|
"graphql": "16.14.2",
|
|
36
36
|
"typescript": "6.0.3",
|
|
37
|
-
"vitest": "
|
|
37
|
+
"vitest": "5.0.1"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|