When using cron trigger with a short interval it can happen that a workflow is running in parallel. When the workflow is chewing through some data the second instance would do the same and this builds up.
For the time being I use a blocker like the one below. But I think this is something that can be handled in an option for the workflow even better.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
260,
-390
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
260,
-140
]
},
{
"parameters": {
"conditions": {
"boolean": [],
"string": [],
"number": [
{
"value1": "= {{$json[\"runningWorkflows\"]}}",
"operation": "larger",
"value2": 1
}
]
}
},
"name": "IF already running",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
880,
-270
]
},
{
"parameters": {},
"name": "NoOp",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1070,
-290
]
},
{
"parameters": {
"functionCode": "const returnItems = [];\nvar runningWorkflows = 0;\n\nfor (const item of $node[\"Get current Executions\"].json[\"data\"]) {\n if(item.workflowId == $workflow.id) {\n runningWorkflows++;\n }\n}\n\nreturnItems.push({json: {\"runningWorkflows\": runningWorkflows}});\n\nreturn returnItems;\n"
},
"position": [
710,
-270
],
"name": "Get runningWorkflows",
"type": "n8n-nodes-base.function",
"typeVersion": 1
},
{
"parameters": {
"url": "={{$node[\"Init\"].parameter[\"values\"][\"string\"][0][\"value\"]}}/rest/executions-current",
"allowUnauthorizedCerts": true,
"jsonParameters": true,
"options": {}
},
"position": [
530,
-270
],
"name": "Get current Executions",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Get current Executions",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Get current Executions",
"type": "main",
"index": 0
}
]
]
},
"IF already running": {
"main": [
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"Get runningWorkflows": {
"main": [
[
{
"node": "IF already running",
"type": "main",
"index": 0
}
]
]
},
"Get current Executions": {
"main": [
[
{
"node": "Get runningWorkflows",
"type": "main",
"index": 0
}
]
]
}
}
}