These are three tools specially useful for automatic recovery after crashes, power cycles, and so on:
1 - CLI Parameters: Worflows can be launched with a "-A" parameter to load a workflows file (.mwf) and send all the workflows in Ready state to the execution queue (and then stay open), or by using "-r" if you want it to do the same but exit Workflows after the inital execution.
2 - OS task scheduling. The Operating System can be told to launch a particular program at startup (for example the Mistika Workflows with the -A parameter ), also restarting the same task it if it dies.
3 - The Workflows "Watcher" node provides properties to retry files being processed at crash time (cont.prev.execution / Number Of Tries)
Practical Example (on Windows): Let's suppose Worflows is installed using the default paths, and we have our workflows file stored here:
C:\My Workflows\My Workflow.mwf
In this example, let's suppose our workflows use a Watcher node that we want to be permanently active, which will be always waiting for new files to land on the watched folder, then passing those files to other nodes for further processing.
Looking at the above options, for this case we will need to launch Workflows with the "-A" parameter, because the other option "-r" would only permit one execution of the workflow and then it will close the application, so no files willl be processed at all. (during the initial execution the Watcher node will not process any files, it will just take note of pre-existing files and install an execution trigger for when newer files appear later).
Then the command that we need is this one:
"C:\Program Files\SGO Apps\Mistika Workflows\bin\workflows.exe -A "C:\My Workflows\My Workflow.mwf"
Before we continue, open a cmd console and execute the above command manually. You should see that it will open Mistika Workflows, then it will load your .mwf file and it will execute all the workfows in Ready state automatically.
Now we can put this command in a scheduled task of the operating system, so that it will force it to be always running. The task scheduler will re-launch in all these situations:
- If the Workflows application crashes
- if the user logout and login again
- After a power cycle or reboot happens (as long as the user is setup with autologin) .
- If a user manually closes the application (if you don't want this to happen you can pause the task in the task scheduler).
Now we will create an operating system task that will load it automatically after the user log on, and then if will check every 5 minutes if it still working or if it crashed, and if it crashed (or if somebody closed it) it will launch it again automatically:
1 - In the windows search field type: Task Scheduler (and press enter)
2 - Click Actions -> Create Task (make sure you click on "Create Task" , not "Create basic task" which is not enough or our purposes). A new dialog "Create Task" will open:
3 - Type a name for the task, for example: "Relaunch Workflows on login and if it crashes"
4 - Activate "Run only when user is logged on" (this is important, as Workflows can not run without a graphics session).
5 - Click on "Configure for:" and select your Windows version (or the most similar to it)
6 - Select Triggers -> "New", and select these options:
* Begin the task -> At log on
* Specific user (your worflows user should be selected)
* Advanced Settings:
Repeat task every -> 5 minutes
For a duration of -> indefinitely
Deactivate "Stop all running tasks at end of repetition duration"
Deactivate "Stop task if it runs longer than"
Deactivate "Activate" and "Expire"
7 - Select Actions -> "New", then select these options (according to the above example):
Action -> Start a program
Program/scrtipt: "C:\Program Files\SGO Apps\Mistika Workflows\bin\workflows.exe"
Add arguments: -A "C:\My Workflows\My Workflow.mwf"
(Don't forget the double quotes in those commands, they are important when there are spaces)
8 - Now in the "Conditions" tab:
Deactivate "Start the task only if the computer is idle for"
Deactivate "Start the task only if the computer is on AC power"
Activate "Wake the computer to run this task"
9 - In the settings tab:
Activate "If the task fails, restart every" and select "1 minute"
Attempt to restart up to: 10 times (logically if it fails more times in a row it does not make sense to try harder, something else must be wrong...)
Deactivate "Stop the task if it runs longer than"
Deactivate "if the running task does not end..."
Deactivate "if the task is not scheduled to run again, delete it after"
Select "If the task is already running, then the following rule applies:
"Do not start a new instance"
10 - Press Ok to finish task creation.
The scheduled task will appear in the task list. It is ready to be tested and it can also be executed manually, but it is not yet active: Last thing we need to do is to logout and login from our user, because we selected "At Log on" as the trigger.
To confirm that it works:
- Logout and login. You should see how Workflows will open, it will load the .mwf file, and it will execute all its workflows automatically.
- Now exit or kill the Workflows application, for example using the Task Manager (to simulate a crash)
- After maximum 5 minutes you should see how it is launched again.
Note: If you need to stop the automatic task for a while, remember that you can always open the Task Scheduler, select the task and disable it temporally.
Watcher node configuration:
There are two properties that will let us to decide what to do after a crash:
cont.prev.execution (Continue Previous Executions) / Number Of Tries: These properties are useful for reacting to software or system crashes. It permits to decide what to do with any files that were being processed at the crash time:
When cont.prev.execution is active, on next execution the Watcher node will retry any files that started a workflow in a previous occasion but didn't complete it (typically due to a crash, blackout, or similar situation).
The Number Of Tries property permits to establish a limit of retries, so if a particular file is crashing workflows every time then it will be skipped after that number of retries.
If cont.prev.execution is disabled then any previous files with uncomplete workflow executions will be simply ignored, and the watcher will wait for new incoming files.
Other related settings
Quiet mode: Adding the -q parameter to the above example permits to execute Mistika Workflows in quiet mode, without showing the GUI interface.
Reacting to blackouts: Most computers permit to define what happens after a blackout when the power is recovered. To react against these situations just make sure they are set to "Power on after blackouts" or similar (the exact funciton depends on each computer model, BIOS, etc), and configure your workflows user for autologin.
Executing a script: Using the -R parameter permits to load Mistika Workflows and execute a python script inside it (note that this is different than using -A or -r, which loads a .mwf file and execute its workflows).
Example (using both -q and -R):
"C:\Program Files\SGO Apps\Mistika Workflows\bin\workflows.exe -q -R "C:\MyScripts\MyPythonScript.py"
For more details read the Python Scripting tools sectio in the Mistika Workflows manual