How to trigger when all nodes before have no more pending items and workflow has multiple SplitInBatches

Dear Community,

I am running a workflow with multiple SplitInBatch-nodes and I want to trigger another part of the workflow after the first part of the workflow has finished, so after all items have passed.

Normally I do that with a IF-node and “{{$node[“SplitInBatches”].context[“noItemsLeft”]}}” but if there are already SplitInBatches-nodes before that and items are coming one by one, this way will fire immediately when there are no more items for a millisecond. Problem is I can also not know how many items are coming to manipulate that IF-node accordingly.

So my question is:

How to I trigger to continue another part of the workflow as soon as all nodes before that trigger have executed and no more items are pending?

Hopefully someone knows how to handle it.
Thank you.

You could send a screen to get an overview of your workflow. You can use the Wait node to add a wait before continuing to run your other nodes. But this is not the best method.

Here a screenshot of the workflow:

image

  1. Small Image Batch - doing Batches of 1
  2. GET Small Image - downloading Images via HTTP Request
  3. Rename Small Image - renaming them
  4. Upload Small Image - pushing images to AWS S3

Yes I thought of a wait node also but the problem is that it is not clear how long the execution is taking and execution time could change all the time.

I want to trigger only after “Upload Small Image” has processed the last image and I tried multiple IF-nodes and also a additional batch on the Upload node, but without success.
Also doing a IF-Node after “GET Small Image” is not working as there is some error on the IF-node that it outputs less number of items than the “Rename Small Image” is receiving. Normally if 15 executions happen, it outputs 13 and I do not know why (using the condition in the first question).

Would be nice to just have a node, that waits untill all previous nodes have finished :slight_smile:

You could create a function to merge all your items into one. This node would act as a filter.

return [
  {
    json: {
      items.map(item => item.json),
    },
  }
];

Hi @prononext

Note completely sure if this is what you looking for, but please give this a look.

EDIT: Sorry I see you already know how to use the if. This wasn’t shown in your example workflow. Could you give the complete workflow for us to have a play with?

Thank you Profile - BramKnuever - n8n, I have tried that. But if you have a SplitInBatch of 1 before, that is not working correctly, as the runs are coming seperate and the second loop is not catching all of them. You can test that, by just having 2 loops after each other.
For instance one to get data and second to aggregate and count after.

HI @prononext

Sorry I don’t think I understand.
I put 2 split in batchs loops after eachother, they work ok.

I am having trouble working out your requirements (I dont understand why you loop back from “GET Small Image” instead of “Uplaod Small Image”), but I will throw this out there in case it helps you find the solution.

In the past when I have used multiple SplitInBatches, I have found it helped to use multiple workflows…if you execute workflow 2 from within workflow 1 then workflow 1 will wait until workflow 2 has done it’s thing, so I move the entire SplitinBatches routine into a separate workflow.

1 Like