2017 © Pedro Peláez
 

library fluent

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

image

aws-swf/fluent

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

  • Saturday, March 22, 2014
  • by cbalan
  • Repository
  • 4 Watchers
  • 9 Stars
  • 1,559 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 5 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

aws-swf-fluent-php

Glue code around aws-sdk-php simple workflow api(Aws\Swf) to allow fluent workflows definition. Feedback is welcome., (*1)

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

  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, (*2)

$domain = new QuickSimpleDomain();
$domain->pollForDecisionTask();

activity-worker.php, (*3)

$domain = new QuickSimpleDomain();
$domain->pollForActivityTask();

Start a workflow execution, (*4)

$domain = new QuickSimpleDomain();
$domain->startWorkflowExecution('threeStepsZen', 5);

More examples

See examples folder for more details, (*5)

The Versions

22/03 2014

dev-master

9999999-dev https://github.com/cbalan/aws-swf-fluent-php

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

  Sources   Download

Apache-2.0

The Requires

 

aws fluent swf

25/07 2013

dev-develop

dev-develop https://github.com/cbalan/aws-swf-fluent-php

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

  Sources   Download

Apache-2.0

The Requires

 

aws fluent swf