Page 1 of 1

Processing One File at a Time

Posted: Tue Nov 19, 2024 9:08 pm
by bdieckman
Hello,

Just wanted to post my solution for processing one file at a time in a Switch flow, since none of the methods I've seen thus far have worked for my use case. The flow is attached as a zip file.

In this flow, jobs are stored in a waiting folder as an indication that the flow is busy. When the flow's activities are complete, the job is deleted from that folder, allowing the next job to be submitted.
Screenshot of flow
Screenshot of flow
Screenshot 2024-11-19 134230.png (28.15 KiB) Viewed 3485 times
  • The outgoing connection of the Hold job element is set to Space Jobs Apart 10 seconds. This ensures that no more than one job ever gets released at a time.
  • A simple PowerShell script (code below) counts the number of PDF files in a folder passed to it in the command line. (If you're not a PowerShell fan this could be JavaScript if you prefer, using the "Script Private Data" element from the Appstore, or a simple find on a Mac)
  • If there is a nonzero number of files returned by the script, the job is sent back to the held folder. Since all the folders up to this point are Auto-managed, these operations are very low overhead.
  • If there are zero files returned by the script, the job is stored locally using a Store it element and is then passed through to the rest of the flow.
  • The flow can go about its business handling that job. (Simulated in this example by a "Hold job" element)
  • Once the flow is finished, the job is sent to an Inject Wildcard element that deletes the job of the same name from the local store, and is then discarded.
Here's the PowerShell script:

Code: Select all

param(
  [Parameter(Mandatory=$true)]
  [string]$folderPath
)

Write-Host (Get-ChildItem $folderPath\*.pdf | Measure-Object).Count;

Re: Processing One File at a Time

Posted: Wed Nov 20, 2024 9:26 am
by tdeschampsBluewest
Hi Bdieckman,
We have developed a such script directly in javascript, that is ready to be released on the Appstore since age.
We are reluctant to release it since if badly implemented by the flow designer, files can be stuck in the flow. (We have a release/timeout mechanic just in case, but still...)

Since you seems to need a such solution, would you be interested to test our solution? (It need Scripting module for now, but i can deploy it on the appstore as a beta with the help of Davy if needed)

Let me know if you are interested!