@webiny/api-headless-cms-es-tasks 6.4.0-beta.2 → 6.4.0-beta.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-es-tasks",
|
|
3
|
-
"version": "6.4.0-beta.
|
|
3
|
+
"version": "6.4.0-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,29 +17,30 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api-core": "6.4.0-beta.
|
|
21
|
-
"@webiny/api-headless-cms": "6.4.0-beta.
|
|
22
|
-
"@webiny/api-headless-cms-ddb-es": "6.4.0-beta.
|
|
23
|
-
"@webiny/api-opensearch": "6.4.0-beta.
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/handler
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/utils": "6.4.0-beta.
|
|
20
|
+
"@webiny/api-core": "6.4.0-beta.4",
|
|
21
|
+
"@webiny/api-headless-cms": "6.4.0-beta.4",
|
|
22
|
+
"@webiny/api-headless-cms-ddb-es": "6.4.0-beta.4",
|
|
23
|
+
"@webiny/api-opensearch": "6.4.0-beta.4",
|
|
24
|
+
"@webiny/background-tasks": "6.4.0-beta.4",
|
|
25
|
+
"@webiny/error": "6.4.0-beta.4",
|
|
26
|
+
"@webiny/handler": "6.4.0-beta.4",
|
|
27
|
+
"@webiny/handler-aws": "6.4.0-beta.4",
|
|
28
|
+
"@webiny/utils": "6.4.0-beta.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webiny/api": "6.4.0-beta.
|
|
32
|
-
"@webiny/build-tools": "6.4.0-beta.
|
|
33
|
-
"@webiny/handler-graphql": "6.4.0-beta.
|
|
34
|
-
"@webiny/plugins": "6.4.0-beta.
|
|
35
|
-
"@webiny/project-utils": "6.4.0-beta.
|
|
36
|
-
"@webiny/wcp": "6.4.0-beta.
|
|
31
|
+
"@webiny/api": "6.4.0-beta.4",
|
|
32
|
+
"@webiny/build-tools": "6.4.0-beta.4",
|
|
33
|
+
"@webiny/handler-graphql": "6.4.0-beta.4",
|
|
34
|
+
"@webiny/plugins": "6.4.0-beta.4",
|
|
35
|
+
"@webiny/project-utils": "6.4.0-beta.4",
|
|
36
|
+
"@webiny/wcp": "6.4.0-beta.4",
|
|
37
37
|
"typescript": "6.0.3",
|
|
38
|
-
"vitest": "4.1.
|
|
38
|
+
"vitest": "4.1.7"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
|
-
"access": "public"
|
|
42
|
-
"directory": "dist"
|
|
41
|
+
"access": "public"
|
|
43
42
|
},
|
|
44
|
-
"
|
|
43
|
+
"webiny": {
|
|
44
|
+
"publishFrom": "dist"
|
|
45
|
+
}
|
|
45
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskDataStatus } from "@webiny/tasks";
|
|
1
|
+
import { TaskDataStatus } from "@webiny/background-tasks/api";
|
|
2
2
|
import { calculateAmounts } from "./calculateAmounts.js";
|
|
3
3
|
import { WAIT_MAX_SECONDS, calculateSeconds } from "./calculateSeconds.js";
|
|
4
4
|
import { createModelAndGroup } from "./createModelAndGroup.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks/MockDataManager/MockDataManager.js","sources":["../../../src/tasks/MockDataManager/MockDataManager.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/tasks\";\nimport type {\n IMockDataManagerInput,\n IMockDataManagerOutput\n} from \"~/tasks/MockDataManager/types.js\";\nimport { calculateAmounts } from \"./calculateAmounts.js\";\nimport type { IMockDataCreatorInput } from \"~/tasks/MockDataCreator/types.js\";\nimport { calculateSeconds, WAIT_MAX_SECONDS } from \"./calculateSeconds.js\";\nimport { createModelAndGroup } from \"~/tasks/MockDataManager/createModelAndGroup.js\";\nimport type { Context } from \"~/types.js\";\nimport { disableIndexing, enableIndexing } from \"~/utils/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { MOCK_DATA_CREATOR_TASK_ID } from \"~/tasks/MockDataCreatorTask.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\n\nexport class MockDataManager<I extends IMockDataManagerInput, O extends IMockDataManagerOutput> {\n constructor(private context: Context) {}\n\n public async execute(\n params: TaskDefinition.RunParams<I, O>\n ): Promise<TaskDefinition.Result<I, O>> {\n const { input, controller } = params;\n\n const taskId = controller.state.getTask().id;\n if (controller.runtime.isAborted()) {\n await this.abortChildTasks(this.context, taskId);\n return controller.response.aborted();\n } else if (input.seconds) {\n const items = await this.listChildTasksNotDone(this.context, taskId);\n\n /**\n * If there are still running creator tasks, we need to wait a bit more.\n */\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input\n },\n {\n seconds: input.seconds || WAIT_MAX_SECONDS\n }\n );\n }\n /**\n * If there are no running tasks, we can enable indexing and finish the manager task.\n */\n await enableIndexing({\n client: this.context.opensearch,\n model: {\n modelId: input.modelId,\n tenant: \"root\"\n }\n });\n return controller.response.done();\n }\n\n const result = await createModelAndGroup({\n context: this.context,\n modelId: input.modelId,\n overwrite: input.overwrite\n });\n if (typeof result === \"string\") {\n return controller.response.done(result);\n }\n\n await disableIndexing({\n model: result.model,\n client: this.context.opensearch\n });\n\n const { amountOfTasks, amountOfRecords } = calculateAmounts(input.amount);\n\n const seconds = calculateSeconds(amountOfRecords);\n\n for (let current = 0; current < amountOfTasks; current++) {\n await controller.task.trigger<IMockDataCreatorInput>({\n definition: MOCK_DATA_CREATOR_TASK_ID,\n input: {\n totalAmount: amountOfRecords,\n createdAmount: 0\n },\n name: `Mock Data Creator Task #${current + 1} of ${amountOfTasks}`\n });\n }\n\n return controller.response.continue(\n {\n ...input,\n seconds,\n amountOfTasks,\n amountOfRecords\n },\n {\n seconds\n }\n );\n }\n\n private async listChildTasksNotDone(context: Context, id: string): Promise<TaskService.Task[]> {\n const { items } = await context.tasks.listTasks({\n where: {\n parentId: id,\n taskStatus_in: [TaskDataStatus.PENDING, TaskDataStatus.RUNNING]\n },\n limit: 10000\n });\n return items;\n }\n\n private async abortChildTasks(context: Context, id: string): Promise<void> {\n const items = await this.listChildTasksNotDone(context, id);\n for (const item of items) {\n await context.tasks.abort({\n id: item.id,\n message: \"Aborted by parent task.\"\n });\n }\n }\n}\n"],"names":["MockDataManager","context","params","input","controller","taskId","items","WAIT_MAX_SECONDS","enableIndexing","result","createModelAndGroup","disableIndexing","amountOfTasks","amountOfRecords","calculateAmounts","seconds","calculateSeconds","current","MOCK_DATA_CREATOR_TASK_ID","id","TaskDataStatus","item"],"mappings":";;;;;;AAeO,MAAMA;IACT,YAAoBC,OAAgB,CAAE;aAAlBA,OAAO,GAAPA;IAAmB;IAEvC,MAAa,QACTC,MAAsC,EACF;QACpC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,MAAMG,SAASD,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;QAC5C,IAAIA,WAAW,OAAO,CAAC,SAAS,IAAI;YAChC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAEC;YACzC,OAAOD,WAAW,QAAQ,CAAC,OAAO;QACtC;QAAO,IAAID,MAAM,OAAO,EAAE;YACtB,MAAMG,QAAQ,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAED;YAK7D,IAAIC,MAAM,MAAM,GAAG,GACf,OAAOF,WAAW,QAAQ,CAAC,QAAQ,CAC/B;gBACI,GAAGD,KAAK;YACZ,GACA;gBACI,SAASA,MAAM,OAAO,IAAII;YAC9B;YAMR,MAAMC,eAAe;gBACjB,QAAQ,IAAI,CAAC,OAAO,CA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f,MACf,MAAML,QAAQ,KAAK,CAAC,KAAK,CAAC;YACtB,IAAIoB,KAAK,EAAE;YACX,SAAS;QACb;IAER;AACJ"}
|
|
1
|
+
{"version":3,"file":"tasks/MockDataManager/MockDataManager.js","sources":["../../../src/tasks/MockDataManager/MockDataManager.ts"],"sourcesContent":["import { TaskDataStatus } from \"@webiny/background-tasks/api\";\nimport type {\n IMockDataManagerInput,\n IMockDataManagerOutput\n} from \"~/tasks/MockDataManager/types.js\";\nimport { calculateAmounts } from \"./calculateAmounts.js\";\nimport type { IMockDataCreatorInput } from \"~/tasks/MockDataCreator/types.js\";\nimport { calculateSeconds, WAIT_MAX_SECONDS } from \"./calculateSeconds.js\";\nimport { createModelAndGroup } from \"~/tasks/MockDataManager/createModelAndGroup.js\";\nimport type { Context } from \"~/types.js\";\nimport { disableIndexing, enableIndexing } from \"~/utils/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { MOCK_DATA_CREATOR_TASK_ID } from \"~/tasks/MockDataCreatorTask.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\n\nexport class MockDataManager<I extends IMockDataManagerInput, O extends IMockDataManagerOutput> {\n constructor(private context: Context) {}\n\n public async execute(\n params: TaskDefinition.RunParams<I, O>\n ): Promise<TaskDefinition.Result<I, O>> {\n const { input, controller } = params;\n\n const taskId = controller.state.getTask().id;\n if (controller.runtime.isAborted()) {\n await this.abortChildTasks(this.context, taskId);\n return controller.response.aborted();\n } else if (input.seconds) {\n const items = await this.listChildTasksNotDone(this.context, taskId);\n\n /**\n * If there are still running creator tasks, we need to wait a bit more.\n */\n if (items.length > 0) {\n return controller.response.continue(\n {\n ...input\n },\n {\n seconds: input.seconds || WAIT_MAX_SECONDS\n }\n );\n }\n /**\n * If there are no running tasks, we can enable indexing and finish the manager task.\n */\n await enableIndexing({\n client: this.context.opensearch,\n model: {\n modelId: input.modelId,\n tenant: \"root\"\n }\n });\n return controller.response.done();\n }\n\n const result = await createModelAndGroup({\n context: this.context,\n modelId: input.modelId,\n overwrite: input.overwrite\n });\n if (typeof result === \"string\") {\n return controller.response.done(result);\n }\n\n await disableIndexing({\n model: result.model,\n client: this.context.opensearch\n });\n\n const { amountOfTasks, amountOfRecords } = calculateAmounts(input.amount);\n\n const seconds = calculateSeconds(amountOfRecords);\n\n for (let current = 0; current < amountOfTasks; current++) {\n await controller.task.trigger<IMockDataCreatorInput>({\n definition: MOCK_DATA_CREATOR_TASK_ID,\n input: {\n totalAmount: amountOfRecords,\n createdAmount: 0\n },\n name: `Mock Data Creator Task #${current + 1} of ${amountOfTasks}`\n });\n }\n\n return controller.response.continue(\n {\n ...input,\n seconds,\n amountOfTasks,\n amountOfRecords\n },\n {\n seconds\n }\n );\n }\n\n private async listChildTasksNotDone(context: Context, id: string): Promise<TaskService.Task[]> {\n const { items } = await context.tasks.listTasks({\n where: {\n parentId: id,\n taskStatus_in: [TaskDataStatus.PENDING, TaskDataStatus.RUNNING]\n },\n limit: 10000\n });\n return items;\n }\n\n private async abortChildTasks(context: Context, id: string): Promise<void> {\n const items = await this.listChildTasksNotDone(context, id);\n for (const item of items) {\n await context.tasks.abort({\n id: item.id,\n message: \"Aborted by parent task.\"\n });\n }\n }\n}\n"],"names":["MockDataManager","context","params","input","controller","taskId","items","WAIT_MAX_SECONDS","enableIndexing","result","createModelAndGroup","disableIndexing","amountOfTasks","amountOfRecords","calculateAmounts","seconds","calculateSeconds","current","MOCK_DATA_CREATOR_TASK_ID","id","TaskDataStatus","item"],"mappings":";;;;;;AAeO,MAAMA;IACT,YAAoBC,OAAgB,CAAE;aAAlBA,OAAO,GAAPA;IAAmB;IAEvC,MAAa,QACTC,MAAsC,EACF;QACpC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAE9B,MAAMG,SAASD,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;QAC5C,IAAIA,WAAW,OAAO,CAAC,SAAS,IAAI;YAChC,MAAM,IAAI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QACJ;IAER;IAEA,MAAc,sBAAsBd,OAAgB,EAAEkB,EAAU,EAA+B;QAC3F,MAAM,EAAEb,KAAK,EAAE,GAAG,MAAML,QAAQ,KAAK,CAAC,SAAS,CAAC;YAC5C,OAAO;gBACH,UAAUkB;gBACV,eAAe;oBAACC,eAAe,OAAO;oBAAEA,eAAe,OAAO;iBAAC;YACnE;YACA,OAAO;QACX;QACA,OAAOd;IACX;IAEA,MAAc,gBAAgBL,OAAgB,EAAEkB,EAAU,EAAiB;QACvE,MAAMb,QAAQ,MAAM,IAAI,CAAC,qBAAqB,CAACL,SAASkB;QACxD,KAAK,MAAME,QAAQf,MACf,MAAML,QAAQ,KAAK,CAAC,KAAK,CAAC;YACtB,IAAIoB,KAAK,EAAE;YACX,SAAS;QACb;IAER;AACJ"}
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OpenSearchContext } from "@webiny/api-opensearch/types.js";
|
|
2
2
|
import type { CmsContext } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
-
import type { Context as TasksContext } from "@webiny/tasks/types.js";
|
|
3
|
+
import type { Context as TasksContext } from "@webiny/background-tasks/api/types.js";
|
|
4
4
|
export type * from "./tasks/MockDataManager/types.js";
|
|
5
5
|
export interface Context extends CmsContext, OpenSearchContext, TasksContext {
|
|
6
6
|
}
|