aws-swf / fluent
Glue code around aws-sdk-php to allow fluent workflows definition
Installs: 1 590
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 4
Forks: 8
Open Issues: 5
Requires
- aws/aws-sdk-php: 2.*
This package is not auto-updated.
Last update: 2025-03-11 07:47:38 UTC
README
Glue code around aws-sdk-php simple workflow api(Aws\Swf) to allow fluent workflows definition. Feedback is welcome.
Features
- Fluent workflow definition
- Transparent domain / workflow type / activity type basic registration
- Basic support for activities, decision tasks and child workflows.
To be implemented / outstanding
- Timer support
- Signal support
- Activity/workflow timeouts support
- ContinueAsNew workflow support
- Workflow/activity cancelation support
- Improved domain/workflow/activity registration
AWS Simple workflow documentation:
- http://aws.amazon.com/swf/
- http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-welcome.html
- http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-workflow-exec-lifecycle.html
Getting Started
- Sign up for AWS - http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/awssignup.html
- Install aws-swf/fluent - Using Composer is the recommended way to install this library.
aws-swf/fluent is available via Packagist under the
aws-swf/fluent
package. - Add your workflows definitions in the same manner as QuickSimpleDomain listed below
- Create long running scripts for decision and activity workers
- Add startWorkflowExecution calls in your php application
Quick Example
Three steps workflow with decision task
class QuickSimpleDomain extends Aws\Swf\Fluent\Domain { /** * Simple workflow domain configuration. * * Mandatory swf objects to be defined here: * - swf domain name using setDomainName method * - swf workflows using addWorkflow method * - actions using workflow's 'to'/registerTask method */ protected function configure() { // set swf client $domain->setSwfClient(Aws\Swf\SwfClient::factory(array( 'key' => 'AWS key', 'secret' => 'AWS secret key', 'region' => 'us-east-1' ))); // set domain name $this->setDomainName('threeStepsZenDomain'); /** * threeStepsZen workflow : * - on start, execute stepOne * - if stepOne failed, execute stepFour. See evaluateStepOneResult method * - if stepOne succeeded, execute stepTwo * - if stepTwo succeeded, execute stepThree * * On any unhandled exception, workflow execution will terminate * with FAIL_WORKFLOW_EXECUTION decision. * Decision tasks can catch/handle previous activity fail/success. */ $this->addWorkflow('threeStepsZen') ->to('activity://stepOne') ->to('decision://evaluateStepOneResult') ->to('activity://stepTwo') ->to('activity://stepThree') ->registerTask('activity://stepFour', array('comment' => 'Optional step 4')); $this->addWorkflow('secondWorkflow') ->to('activity://stepBeforeChildWorkflow') ->to('childWorkflow://threeStepsZen') ->to('activity://stepAfterChildWorkflow'); } public function stepOne($context) { /* do something on activity workers.*/ } public function evaluateStepOneResult($context, $decisionHint) { $lastEvent = $decisionHint->getLastEvent(); if ($lastEvent['eventType'] == Aws\Swf\Enum\EventType::ACTIVITY_TASK_FAILED) { $decisionHint->setItem($this->getActivity('stepFour')); $decisionHint->setDecisionType(Aws\Swf\Enum\DecisionType::SCHEDULE_ACTIVITY_TASK); } } public function stepTwo($context) { /* do something on activity workers.*/ } public function stepThree($context) { /* do something on activity workers.*/ } public function stepFour($context) { /* do something on activity workers.*/ } public function stepBeforeChildWorkflow($context) { /* do something on activity workers.*/ } public function stepAfterChildWorkflow($context) { /* do something on activity workers.*/ } }
decision-worker.php
$domain = new QuickSimpleDomain(); $domain->pollForDecisionTask();
activity-worker.php
$domain = new QuickSimpleDomain(); $domain->pollForActivityTask();
Start a workflow execution
$domain = new QuickSimpleDomain(); $domain->startWorkflowExecution('threeStepsZen', 5);
More examples
See examples folder for more details