Simple way to check if a workflow is running

I have seen various questions from people asking how to check to see if a workflow is running, most recently here.

I never needed this exact functionality but I decided to put together a workflow anyway for anyone it would help.

It just saved a file with a unique ID at the beginning of the workflow and deletes it at the end. The first step of the workflow checks if that file exists. It will only exist if a workflow with the same ID is already running.

edit: I have added more features and updated the post after some feedback. I also added a version that uses spreadsheets in a comment lower down for cloud users

I explained in the notes on the workflow canvas

Feel free to ask any questions!

5 Likes

Well, that’s great. The only possible issue is when n8n will get OOM or other unexpected error during the execution, so it will lock some workflows :slight_smile:

I would add a timestamp of the last file or check how long that file is there and if too long (in regards to usual workflow execution behavior) then delete the file to release the lock.

Unfortunately that approach can’t be used on the cloud as there is no Execute Command Node there :slight_smile:
But it can be also done with the getWorkflowStaticData variable

1 Like

yeah, that’s why I put the example to handle an error in the middle. Time stamp is a good idea to improve that and to make oom issues less painful

OOM could be an issue, but this could be added to to handle that stuff. I very rarely have memory issues so it’s not usually something I think about

People who are on cloud could use external storage like any database or spreadsheet, but honestly did forget about that and think I made this for someone on cloud, whoops

EDIT: I added time stamps and error handling for out of memory issues since this comment, they are in the edited workflows on this post

Cloud Users Use This

Here is the same idea but with a google sheet. The spreadsheet will work fine for light use, but i recommend using a proper database for mission critical workflows.

You’ll just need to connect a spreadsheet with a header row of ID and TimeStamp, everything else should be plug and play

Make sure you set all the spreadsheets to retry if failed with a 5000ms delay incase of rate limiting

1 Like