Skip to content

cbalan/aws-swf-fluent-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-swf-fluent-php

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:

Getting Started

  1. Sign up for AWS - http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/awssignup.html
  2. 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.
  3. Add your workflows definitions in the same manner as QuickSimpleDomain listed below
  4. Create long running scripts for decision and activity workers
  5. 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

About

Glue code around aws-sdk-php to allow fluent workflows definition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages