I have this workflow that reads a Google Drive directory, then loops through files and folders listed using a Switch node. For each Drive object, if the object is a file, it’s passed on to Supabase node, and if it’s a folder, the folder’s ID is passed to a node that lists the objects within that folder, which then passes those objects BACK to the switch that determines if the object is a file or folder. What happens in this workflow is multiple “batches” of files are sent to the Supabase node, causing multiple “runs” in the workflow.
What I want is to determine when the whole workflow is done (i.e. all the files have been loaded into Supabase), and THEN perform a final action. However, whenever I add a node after the Supabase node, it’s triggered once for EVERY RUN of file batches.
Researching the N8n documentation and forums and community, I haven’t found any way to do this. Is there is a way to trigger an action after ALL the runs have been completed?
Hi i guess the best way to do that is using loop batch so you can add another action after the main task over but im concern about your logic to search another file, is it will contain more than 1 file again?
This is generally the best solution by using a loop node. The other cheap hack is to add an Aggregate node after the supabase step which will essentially take all items and return a single array item causing the next node after that to only execute once.
Thanks! I tried this, but due to the nature of the search process, the loop runs once for each level of directory depth. So I still get multiple runs out of the loop node, when I just want one. I could manually have the aggregate node run once, but it doesn’t have the complete file listing on the first hit, so it’s not an accurate signal that the search has actually completed.
If you’re trying to traverse n levels of directories and read files, then you would traditionally do this using a recursive function. In the case of n8n you would create another workflow to act as the function of reading a dir and its files and then pass the next folder to itself recursively.
Can you suggest how to modify this workflow to do what you’re describing? When I’ve previously attempted to break out a subworkflow to do the folder search, it still results in multiple runs of the primary workflow, the same as if the recursive logic is contained in a single workflow.
It would be hella nice to solve, yes. For now, my workaround is having the listing workflow immediately send a webhook GET when it starts, and then the subsequent steps are broken off into a separate workflow that runs after receiving the webhook GET and Waiting a guessed amount of time (probably too long) for the file listing workflow to run. Pretty janky.
Based on your workflow idea, it seems the workflow should end when the Google Drive node “Search Subfolders” does not output any folders. So, all you need to do is check whether there are any folders in its output.
To do this, connect the “Search Subfolders” node to an IF node. This IF node will check if any folders exist in the output. If one or more folders are found, the loop will continue. If not, the loop will break, and the workflow will continue to another Supabase node named “Supabase_2” to load the remaining files. After that, you can proceed with your final action after the “Supabase_2’” node.