UNPKG

@apify/n8n-nodes-apify

Version:
65 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runTaskAndGetDataset = runTaskAndGetDataset; const n8n_workflow_1 = require("n8n-workflow"); const genericFunctions_1 = require("../../genericFunctions"); const helpers_1 = require("../../../helpers"); async function runTaskAndGetDataset(i) { var _a; const actorTaskId = this.getNodeParameter('actorTaskId', i, undefined, { extractValue: true, }); const rawStringifiedInput = this.getNodeParameter('customBody', i, '{}'); const timeout = this.getNodeParameter('timeout', i, null); const memory = this.getNodeParameter('memory', i, null); const build = this.getNodeParameter('build', i, ''); let input; try { input = (0, genericFunctions_1.customBodyParser)(rawStringifiedInput); } catch { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Could not parse custom body: ${rawStringifiedInput}`); } if (!actorTaskId) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Task ID is required'); } const qs = {}; if (timeout != null) qs.timeout = timeout; if (memory != null) qs.memory = memory; if (build) qs.build = build; qs.waitForFinish = 0; const apiResult = await genericFunctions_1.apiRequest.call(this, { method: 'POST', uri: `/v2/actor-tasks/${actorTaskId}/runs`, body: input, qs, }); if (!((_a = apiResult === null || apiResult === void 0 ? void 0 : apiResult.data) === null || _a === void 0 ? void 0 : _a.id)) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `Run ID not found after running the task`, }); } const runId = apiResult.data.id; const lastRunData = await genericFunctions_1.pollRunStatus.call(this, runId); if (!(lastRunData === null || lastRunData === void 0 ? void 0 : lastRunData.defaultDatasetId)) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `Run ${runId} did not create a dataset`, }); } if ((lastRunData === null || lastRunData === void 0 ? void 0 : lastRunData.status) !== 'SUCCEEDED') { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `Run ${runId} did not finish with status SUCCEEDED. Run status: ${lastRunData === null || lastRunData === void 0 ? void 0 : lastRunData.status}`, }); } const datasetItems = await genericFunctions_1.apiRequest.call(this, { method: 'GET', uri: `/v2/datasets/${lastRunData.defaultDatasetId}/items`, qs: { format: 'json' }, timeout: helpers_1.consts.DATASET_REQUEST_TIMEOUT_MS, }); return this.helpers.returnJsonArray(datasetItems); } //# sourceMappingURL=execute.js.map