Check for running Task

Is there an action to check if a task is currently running on the server? I'd like to skip calling a task to run if it's already running so it does not error out. Basically looking for an option here that says don't fail if task is running.

image


Something similar to this:

image

Getting task status is possible with the EasyMorph Server CLI, but not with the "EasyMorph Server command" action yet.

See the gettask command of the ems-cmd command-line utility: GitHub - easymorph/server-cmd: Command line API client for EasyMorph Server

Thanks for the suggestion, but it doesn't let me know if it's running.

image

You're correct. I forgot that we removed this field from task properties when we added the ability to run multiple instances of a task.

For now, there is no API/command to receive information if there are any running instances of a task. We will add it to the roadmap.

1 Like

Honestly, if you could just make it so this action doesn't cause the model to fail, that would solve my issues.

image

1 Like

While it's probably too late, but I just figured out a workaround:

In the task, set (remember) a Shared Memory key at the start of the task and delete it (forget) at the end of the task.

In the workflow that triggers the task, check if that Shared Memory key is set, and if yes - skip triggering the task.

Alternatively, enable multiple simultaneous instances of the task (parallel execution), and in the start of the task check if the Shared Memory key is set. If yes - exit, otherwise set the key and keep running. Delete the key at the end. In this scenario, the logic is shifted from the calling workflow, to the called task.

Thanks, I haven't used the shared memory action before. That seems like it might work for what I need. Appreciate it.

I took your idea and added a Repeat action so that it will just put the model on hold until the process finishes running and deletes the shared memory then proceeds. Thanks for the idea.

This is a great use of the "Repeat" action :+1:

If your intent was to delay execution, not to skip it (as I assumed initially), then it can be done even simpler:

Wrap the "Server command" action that runs the task with the "Exclusive access" action. Put "Start exclusive access" before the command, and "Finish exclusive access" right after it. That's it. No need to use Shared Memory or Repeat. Make sure to use the same resource name in the Start and Finish actions (before and after) so that the finish can be related to the start.

When the action starts exclusive access, then any other workflow that tries to start exclusive access with the same resource name will wait until the first workflow finishes access (releases the resource).

The only downside compared with the "SharedMemory + Repeat" combination is that "Exclusive access" only works for workflows running on the same computer, while using Shared Memory + Repeat allows managing access by workflows on different computers as long as they work with the same Server repository.

1 Like

Thanks, I learned a new action today. My initial intent was to just skip if it was running, but there are certain cases where I needed it to wait and then run. I'll probably keep the sharedmemory as models are being run across multiple machines. But the exclusive access will be helpful in other spots for me.