blainelang
8/29/2013 - 8:06 PM

Using the maestro API to launch a new workflow instance, crank the engine and get process detail. Sample PHP code to interact with the Drupa

Using the maestro API to launch a new workflow instance, crank the engine and get process detail. Sample PHP code to interact with the Drupal maestro module (workflow engine) https://drupal.org/project/maestro

// Helper function to instantiate maestro engine and step it forward
maestro_orchestrator();

// Alternative method to interact with the maestro engine API
$maestro = Maestro::createMaestroObject(1);
/*
That's it!  Wherever you want to run the orchestrator, you will place that code.
If you look in maestro.module, you will find the function maestro_orchestrator.  
Inside of it we are trying to acquire a lock based on a defined lock delay (in seconds) configuration parameter.
The lock is essentially a simple lock semaphore.  If for some reason the lock is not relinquished in a default of 512 seconds,
the orchestrator can be run again.  You can tune that parameter in the maestro config.
Running maestro_orchestrator() makes sure that only one instance of the orchestrator is running.
The function of maestro_orchestrator shows how you actually at the api level, run through the queue (cleanQueue method).
DO NOT directly call cleanQueue.  you will get race conditions.
*/


// Instantiate the maestro engine and launch a new workflow instance
$maestro = Maestro::createMaestroObject(1);
$newprocess = $maestro->engine()->newProcess($template);

// Retrieve details for a running workflow instance
$process_data = $maestro->engine()->getQueueHistory($new_process_id);