The Maestro Engine is the mechanism responsible for executing a workflow template by assigning tasks to actors, executing tasks for the engine and providing all of the other logic and glue functionality to run a workflow.  The maestro module is the core module in the Maestro ecosystem and is the module that houses the template, variable, assignment, queue and process schema.  The maestro module also provides the Maestro API for which developers can interact with the engine to do things such as setting/getting process variables, start processes, move the queue along among many other things.

As noted in the preamble for our Maestro D8 Concepts Part 1: Templates and Tasks post, there is jargon used within Maestro to define certain aspects of the engine and data.  The major terms are as follows:


Template:  The workflow pattern which you can edit via the Template Builder module.  Defines the logical pattern the engine should follow.

Tasks:  Tasks are defined in the Template Builder and are either executed by the engine or assigned to actors.  

Template Variables:  Variables defined on a template and used in the Template Builder for logical operations, task operations or task assignments.

During Template Execution:

Process:  When a template has been started (there are multiple ways to start a template), the template is used by the engine as the path for execution.  Thus, the first entity created by the engine when a template is started is the process entity.  Thus a template put into production is a process and each process has it's own unique ID called the process ID.  

Queue:  The queue is the entity that holds information for what the engine is to execute or what is presented to the task console for the assigned actors to execute.  Each task in the template becomes an entry in the queue when a template has been put into production.  Only those tasks which are ready to be executed are created in the queue table by the engine.

Process Variables:  Template variables that have been copied over into the execution process variables entity to track and store variables.  Using the Maestro API, developers can get/set values, tasks can be assigned and logic tests can be done on variable values.  Variable values can be unique from process to process, thus producing routing or logic operations that are different from process to process even if those processes are based on the same template.

Production Assignment:  Tasks are assigned to actors or roles either explicitly or by variable in the template builder.  When a template is put into production, those assignments are translated from the template and injected into the production assignments entity.  Only interactive tasks such as the interactive task, manual web task and content type task (shipped by Maestro at this point) are assignable to human actors.  Thus only those task types will have production assignments in the production assignments entity.  Engine executable tasks are simply executed by Maestro.

The Orchestrator:  The Orchestrator is the crucial piece to the Maestro puzzle.  The Orchestrator is responsible for marshalling the process to completion.  There is one and only one instance of the orchestrator that is allowed to run at any given time, thus forcing the movement of processes forward task-by-task.  It is highly recommended that the Orchestrator be run on a relatively frequent basis via the Orchestrator URL (http://site_url/orchestrator/{token}).  You can also run the Orchestrator via refreshes of the Task Console.  You can configure the Orchestrator by going to /admin/config/workflow/maestro, and setting a token to be used in the Orchestrator URL and turning on/off the execution via the Task Console.  Setting the Orchestrator to run every minute is not uncommon and allows processes to continue without the need to hit the Task Console to move the processes forward.



Task Completion:  When a task completes, the software flags the task's status as being complete.  During the Orchestrator's execution, it reads the status of the task and determines if it has been completed and will flag the task as "archived" once the next task in the template has been created.  

Process Completion:  When the End task is executed, the engine will execute code to flag the process as complete.  If a process has open tasks appearing in users' Task Consoles and the process is flagged as completed, those tasks disappear as only active processes and active process' tasks are actioned upon by Maestro.  If you do not have an End task for any flows that can have multiple end points, the process will never be flagged as complete unless you flag it as such via the Maestro API.

Validation:  New for Maestro on Drupal 8, the validation engine helps ensure that templates are created properly and that the template has a higher probability of executing error free (no guarantees as the engine has no concept if a user SHOULD be assigned to tasks or if your logic is sound).  Thus when you make changes to a template in the template builder, the template is flagged as invalid and cannot be put into production if it has not been validated.