How is workflow run if cron is connected to multiply nodes

So I have pretty complicated workflow and is pretty important for me to some nodes be not run before other

I checked multiply times, and it works from the beginning to the bottom, but can I be sure about that or it was just coincident?

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -1020,
        140
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Done or cancelled|checkbox",
                    "condition": "equals",
                    "checkboxValue": true
                  },
                  {
                    "key": "Recurring|select",
                    "condition": "is_not_empty"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Get ready to reschedule",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        0,
        340
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const moment = require(\"moment\")\n\nfor (item of items) {\n  // get date value to whitch we will add some days/weeks or so\n  if(item.json.Fixed)\n    newDate = item.json.Date.start\n  else\n    newDate = item.json['Edited at']\n\n  // create moment obj\n  newDate = moment(newDate.substr(0, 10))\n  \n  // Add perios\n  index = item.json.Recurring.search(\" \")\n  \n  quantity = item.json.Recurring.substr(0, index)\n  period = item.json.Recurring.substr(index + 1)\n  \n  // finally add period\n  item.json.newDate = newDate.add(quantity, period)\n}\n\nreturn items;"
      },
      "name": "Calculate new date",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        240,
        340
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "={{$json[\"newDate\"]}}"
            },
            {
              "key": "Done or cancelled|checkbox"
            }
          ]
        }
      },
      "name": "Update tasks with new date",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        460,
        340
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 5
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        -420,
        780
      ]
    },
    {
      "parameters": {},
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        240,
        0
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Recurring|select",
                    "condition": "is_not_empty"
                  },
                  {
                    "key": "Project|checkbox",
                    "condition": "equals",
                    "checkboxValue": true
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Get recurring and project",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        0,
        -140
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Done or cancelled|checkbox",
                    "condition": "equals"
                  },
                  {
                    "key": "Fixed|checkbox",
                    "condition": "equals"
                  },
                  {
                    "key": "Recurring|select",
                    "condition": "is_empty"
                  },
                  {
                    "key": "Date|date",
                    "condition": "on_or_before",
                    "date": "={{new Date().toISOString()}}"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Get Yesterday unfixed & unfinished tasks",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        -20,
        960
      ],
      "alwaysOutputData": false,
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "9999-12-30T23:00:00.000Z"
            }
          ]
        }
      },
      "name": "Remove dates",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        240,
        960
      ],
      "alwaysOutputData": true,
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{(new Date().getDay() % 6) == 0}}",
              "value2": true
            }
          ]
        }
      },
      "name": "Check week day",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        100,
        1220
      ],
      "notesInFlow": true,
      "notes": "If true; weekend; else; Mon-Fri"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "or": [
                  {
                    "key": "Date|date",
                    "condition": "is_empty"
                  },
                  {
                    "key": "Date|date",
                    "condition": "on_or_after",
                    "date": "9998-12-31T23:00:00.000Z"
                  },
                  {
                    "key": "Date|date",
                    "condition": "on_or_before",
                    "date": "={{new Date().toISOString()}}"
                  }
                ]
              }
            }
          },
          "sort": {
            "sortValue": [
              {
                "key": "Priority|checkbox",
                "direction": "descending"
              },
              {
                "key": "Created at|created_time",
                "direction": "ascending"
              }
            ]
          }
        }
      },
      "name": "Get unfixed tasks",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        340,
        1240
      ],
      "executeOnce": true,
      "retryOnFail": true,
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "items = items.filter(item => !item.json['Done or cancelled'])\nitems = items.filter(item => !item.json['Fixed'])\nitems = items.filter(item => item.json['Recurring'] == undefined)\nitems = items.filter(item => item.json['Project'])\n\nitems = items.slice(0, 1)\n\n\nreturn items;"
      },
      "name": "1 project",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        580,
        1140
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "functionCode": "items = items.filter(item => !item.json['Done or cancelled'])\nitems = items.filter(item => !item.json['Fixed'])\nitems = items.filter(item => item.json['Recurring'] == undefined)\nitems = items.filter(item => !item.json['Project'])\n\nitems = items.slice(0, 4)\n\n\nreturn items;"
      },
      "name": "4 default tasks",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        580,
        1340
      ],
      "notesInFlow": true
    },
    {
      "parameters": {},
      "name": "Merge them",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        840,
        1260
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "={{new Date()}}"
            }
          ]
        }
      },
      "name": "Set Today date",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1060,
        1260
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {},
      "name": "Weekend is free of tasks",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        680,
        920
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Project|checkbox",
                    "condition": "equals",
                    "checkboxValue": true
                  },
                  {
                    "key": "Done or cancelled|checkbox",
                    "condition": "equals"
                  },
                  {
                    "key": "Date|date",
                    "condition": "is_not_empty"
                  },
                  {
                    "key": "Date|date",
                    "condition": "before",
                    "date": "9998-12-31T23:00:00.000Z"
                  },
                  {
                    "key": "Fixed|checkbox",
                    "condition": "equals"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Get unfixed projects with deadline",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        0,
        620
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const moment = require(\"moment\")\n\n// https://stackoverflow.com/a/28425663/8846153\nfunction workday_count(start,end) {\n  var first = start.clone().endOf('week'); // end of first week\n  var last = end.clone().startOf('week'); // start of last week\n  var days = last.diff(first,'days') * 5 / 7; // this will always multiply of 7\n  var wfirst = first.day() - start.day(); // check first week\n  if(start.day() == 0) --wfirst; // -1 if start with sunday \n  var wlast = end.day() - last.day(); // check last week\n  if(end.day() == 6) --wlast; // -1 if end with saturday\n  return wfirst + Math.floor(days) + wlast; // get the total\n} //  \n\nitems = items.filter(item => workday_count(new moment(), new moment(item.json.Date.start)) <= 3)\nitems = items.filter(item => moment(item.json.Date.start) > moment())\n\n\nreturn items;"
      },
      "name": "Filter for only with <= 3 working days left",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        260,
        500
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "={{new Date}}"
            },
            {
              "key": "Fixed|checkbox",
              "checkboxValue": true
            }
          ]
        }
      },
      "name": "Make them fixed",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        500,
        520
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Recurring|select",
                    "condition": "is_not_empty"
                  },
                  {
                    "key": "Date|date",
                    "condition": "is_empty"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Get recurring without date",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        0,
        100
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/921134300471107634/Sxg0lL7rU1yIvRq4OomdkEYTk3TFq-A8SRAHnmPmoko7pdo9JDN74FIrm5Q2LCA-nR7x",
        "text": "=**Error**\nName: {{$json[\"Name\"]}}\nLink: https://www.notion.so/shirobachi/{{$json[\"id\"].replace(/-/g, \"\")}}\nProblem: {{$json[\"Label error\"]}}"
      },
      "name": "Push to discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        460,
        0
      ]
    },
    {
      "parameters": {
        "functionCode": "const moment = require(\"moment\")\n\n// https://stackoverflow.com/a/28425663/8846153\nfunction workday_count(start,end) {\n  var first = start.clone().endOf('week'); // end of first week\n  var last = end.clone().startOf('week'); // start of last week\n  var days = last.diff(first,'days') * 5 / 7; // this will always multiply of 7\n  var wfirst = first.day() - start.day(); // check first week\n  if(start.day() == 0) --wfirst; // -1 if start with sunday \n  var wlast = end.day() - last.day(); // check last week\n  if(end.day() == 6) --wlast; // -1 if end with saturday\n  return wfirst + Math.floor(days) + wlast; // get the total\n} //  \n\nitems = items.filter(item => workday_count(new moment(), new moment(item.json.Date.start)) <= 5)\nitems = items.filter(item => moment(item.json.Date.start) > moment())\n\n\nreturn items;"
      },
      "name": "Filter for only with <= 5 working days left",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        260,
        740
      ],
      "notesInFlow": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Priority|checkbox",
              "checkboxValue": true
            }
          ]
        }
      },
      "name": "Make then priority (unfixed still)",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        500,
        740
      ],
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    }
  ],
  "connections": {
    "Get ready to reschedule": {
      "main": [
        [
          {
            "node": "Calculate new date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate new date": {
      "main": [
        [
          {
            "node": "Update tasks with new date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Get recurring and project",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get recurring without date",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get ready to reschedule",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get unfixed projects with deadline",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Yesterday unfixed & unfinished tasks",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check week day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Push to discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get recurring and project": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Yesterday unfixed & unfinished tasks": {
      "main": [
        [
          {
            "node": "Remove dates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check week day": {
      "main": [
        [
          {
            "node": "Weekend is free of tasks",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get unfixed tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get unfixed tasks": {
      "main": [
        [
          {
            "node": "4 default tasks",
            "type": "main",
            "index": 0
          },
          {
            "node": "1 project",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1 project": {
      "main": [
        [
          {
            "node": "Merge them",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4 default tasks": {
      "main": [
        [
          {
            "node": "Merge them",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge them": {
      "main": [
        [
          {
            "node": "Set Today date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get unfixed projects with deadline": {
      "main": [
        [
          {
            "node": "Filter for only with <= 3 working days left",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filter for only with <= 5 working days left",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter for only with <= 3 working days left": {
      "main": [
        [
          {
            "node": "Make them fixed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get recurring without date": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Filter for only with <= 5 working days left": {
      "main": [
        [
          {
            "node": "Make then priority (unfixed still)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

It executes in the order the connections got created. The actual location of the nodes in the flow does not matter.

If you want to be 100% sure that the nodes execute in the order you want them to be executed, you should connect them in the correct order. Meaning probably first the four nodes on the top, then the three nodes below, …

3 Likes

Having same problem. So if I disconnect all nodes and then reconnect in the order I want these run it should work. Now… Will the next node (connection) be ran after the first whole branch? Or will it run in parallel branches?

Thanks!

Sorry, do not understand.

Generally nothing runs in parallel. Always one node after another executes.

1 Like