Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Execute Workflow Node): Run once for each item mode (#7289)
Github issue / Community forum post (link here to close automatically):
- Loading branch information
1 parent
597669a
commit c8c14ca
Showing
3 changed files
with
149 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/nodes-base/nodes/ExecuteWorkflow/GenericFunctions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
NodeOperationError, | ||
type IExecuteFunctions, | ||
type IExecuteWorkflowInfo, | ||
jsonParse, | ||
} from 'n8n-workflow'; | ||
|
||
import { readFile as fsReadFile } from 'fs/promises'; | ||
|
||
export async function getWorkflowInfo(this: IExecuteFunctions, source: string, itemIndex = 0) { | ||
const workflowInfo: IExecuteWorkflowInfo = {}; | ||
|
||
if (source === 'database') { | ||
// Read workflow from database | ||
workflowInfo.id = this.getNodeParameter('workflowId', itemIndex) as string; | ||
} else if (source === 'localFile') { | ||
// Read workflow from filesystem | ||
const workflowPath = this.getNodeParameter('workflowPath', itemIndex) as string; | ||
|
||
let workflowJson; | ||
try { | ||
workflowJson = await fsReadFile(workflowPath, { encoding: 'utf8' }); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
throw new NodeOperationError( | ||
this.getNode(), | ||
`The file "${workflowPath}" could not be found, [item ${itemIndex}]`, | ||
); | ||
} | ||
|
||
throw error; | ||
} | ||
|
||
workflowInfo.code = jsonParse(workflowJson); | ||
} else if (source === 'parameter') { | ||
// Read workflow from parameter | ||
const workflowJson = this.getNodeParameter('workflowJson', itemIndex) as string; | ||
workflowInfo.code = jsonParse(workflowJson); | ||
} else if (source === 'url') { | ||
// Read workflow from url | ||
const workflowUrl = this.getNodeParameter('workflowUrl', itemIndex) as string; | ||
|
||
const requestOptions = { | ||
headers: { | ||
accept: 'application/json,text/*;q=0.99', | ||
}, | ||
method: 'GET', | ||
uri: workflowUrl, | ||
json: true, | ||
gzip: true, | ||
}; | ||
|
||
const response = await this.helpers.request(requestOptions); | ||
workflowInfo.code = response; | ||
} | ||
|
||
return workflowInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters