Is there a way to allow only one instance to run at a time with a Workflow?

Options

Use Case: I have webform trigger that revises an Excel file on Sharepoint. The revision process is fast and takes only about two minutes, but if I fire the webform trigger two times in a row, the first revision request gets overwritten by the second request. I envision a few ways to prevent this:
1. The Sharepoint REST API's have a checkout and checkin feature for this purpose. However, if Catalytic checks out the Excel file on the first trigger, when the second trigger comes along, since the username is also Catalytic (or whatever name is in the integration), I don't think this would block the second trigger from working with the Excel file, because it would think it's the same person (entity) trying to revise the Excel file.
2. I could temporarily delete the Excel file on any trigger, to prevent any subsequent triggers from working with it. But this would throw an error for the second request sent while the first one was working (which I could handle, perhaps have it look for the error code that 'no file was downloaded' and have it wait to try again in two minutes.) When the first request is finished and the Excel file is ready to be worked with again, it could be uploaded back to Sharepoint.
3. What I am hoping for is that with Catalytic, there is a way I can work with the global fields to check if an instance is running for a given workflow. Like maybe check that there are run stop dates/times associated with every run start time? Or do I have to separate this single workflow into two workflows, and have some type of queue system so that the second workflow (working with the Excel file) is only running one at a time?

thank you!
Kevin

Tagged:

Answers

  • Thomas_937381
    Options

    @Kevin_579059 Could you use the workflow's master table?

    That table has a column called Instance status, which you could first use to check if there are is more than one instance 'running'. If not, proceed; if yes, loop.

    Do you know the rate at which the web form trigger will be submitted? The reason I ask is because after that I envision a (delayed) loop (Workflow: Reopen task and reset dependent tasks) that conditionally checks if the [reformatted] run.startDate is the lowest value in the Process start date column. That paired with the Instance run ID should allow you to build logic to skip the loop if the current run is the oldest pending one, and continue.

    You'll want to be deliberate about the delays in your loops, and think about submission rate, so that you don't exceed the instance task limit.

    Because you're using the master table, also keep in mind that test runs won't be visible as a line, so you need production starts of the workflow to test. You can always convert those later on, if need be.

  • Kevin_579059
    Options

    @Thomas_937381 Thank you!
    If I understand correctly, when the process starts, it will create a run with the status "running." So if there is another process already running, then the run "count" will be greater than 1. So this would be the first check. If the run count is not greater than 1, then the newly created run can proceed. This seems easy.
    But if the count is greater than 1, then there needs to be sort of a queue set up where it will look for the oldest start date, to make sure that run goes next.
    I don't know the trigger rate, but it should be relatively low, so I'm not worried about the task limits.
    I will try this out!
    Kevin

  • Kevin_579059
    Options

    @Thomas_937381 Can you check my workflow? I created a practice one called "Testing Workflow Instance Status." I think I am having trouble with the syntax in the loop step "reopen taskone"

    I have the initial step running fine, that it skips this loop if there is only one instance running.
    For the loop, I have similar logic to what you suggested, but I am using Tables: Look Up in the Master Data Table in the Instance Status column for the Instance ID of "running", and given that the Master Data Table shows the instances in order, it will return the first Instance, which should be the "next one up."
    Then in this loop step, I am checking the "next up" ID against the current run ID.
    I think I am having trouble with the syntax, because the loop is not stopping. I have checked the output of "run-id-next-up--Instance run ID" and it is indeed showing the next one up.
    thanks!
    Kevin

  • Thomas_937381
    Options

    @Kevin_579059 Could you please email me the process URL, thomas@catalytic.com?

    Otherwise, I would not use the Mark complete if parameter, and instead use a condition (keeping in mind the condition would need to be adjusted). The parameter you pointed to is more useful if you have a really complex set of conditions.

  • Kevin_579059
    Options

    @Thomas_937381 I think I got it to work! Moving the "stop loop" to the condition was easier. I used Field Formulas to convert runID to a variable that can be used in the condition. I now just need to implement this into my main workflow.
    If I have time, and I can pare down the "practice" workflow, I will share it in Show and Tell.