2017 © Pedro Peláez
 

library conductor

php client for netflix conductor

image

mobiletech/conductor

php client for netflix conductor

  • Friday, May 18, 2018
  • by ChrisLe
  • Repository
  • 0 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 50 % Grown

The README.md

conductor-client-for-php

Install, (*1)

composer require mobiletech/conductor, (*2)

Require PHP 7.2 or later with ZTS, (*3)

How to use, (*4)

  • Start a workflow, (*5)

    $conductorHost = 'localhost';
    $conductorPort = 8080;
    $conductorRootUri = "http://{$conductorHost}:{$conductorPort}/api/";
    $workflowName = 'test-workflow';
    $workflowVersion = 1;
    
    $inputMap = [
        'foo' => 'foo',
        'bar' => 'bar'
    ];
    
    
    $startWorkflowRequest = new StartWorkflowRequest();
    $startWorkflowRequest->withName($workflowName)
        ->withVersion($workflowVersion)
        ->withCorrelationId('1') // Optional, use for tracking workflow by correlationId  
        ->withInput($inputMap);
    
    $workflowClient = new WorkflowClient();
    $workflowClient->rootUri = $conductorRootUri;
    
    $wfId = $workflowClient->startWorkflow($startWorkflowRequest);
    
    echo sprintf("{$wfId} \n");
    
  • Create a worker for conductor, (*6)

    use conductor\client\worker\ConductorWorker;
    use conductor\common\metadata\tasks\ConductorTask;
    use conductor\common\metadata\tasks\ConductorTaskStatus;
    use conductor\common\metadata\tasks\TaskResult;
    
    class DemoWorker extends ConductorWorker
    {
        /**
         * Name of the worker task
         * @var string
         */
        private $taskDefName;
    
        /**
         * Limit number of tasks returned when poll from Conductor server
         * @var int
         */
        private $pollCount;
    
        public function __construct(string $taskDefName, int $pollCount)
        {
            $this->taskDefName = $taskDefName;
            $this->pollCount = $pollCount;
        }
    
        function getTaskDefName(): string
        {
            return $this->taskDefName;
        }
    
        function getPollCount(): int
        {
            return $this->pollCount;
        }
    
        function execute(ConductorTask $task): TaskResult
        {
            $taskResult = new TaskResult($task);
            $inputData = $task->inputData;
            try{
                $foo = $inputData->foo;
                $bar = $inputData->bar;
    
                $outputData = [
                    'foo' => $foo,
                    'bar' => $bar
                ];
    
                $taskResult->outputData = $outputData;
                $taskResult->status = ConductorTaskStatus::COMPLETED;
                $taskResult->Log('This is log for worker task');
            } catch (Exception $e) {
                $taskResult->status = ConductorTaskStatus::FAILED;
                $taskResult->Log($e->getMessage());
            }
            return $taskResult;
        }
    }  
    
  • Init conductor workers, (*7)

    $conductorHost = 'localhost';
    $conductorPort = 8080;
    $conductorRootUri = "http://{$conductorHost}:{$conductorPort}/api/";
    $threadCount = 2; // Available number of thread to execute tasks
    
    $workerList = [];
    $workerList[] = new DemoWorker("demo_worker", 20);
    
    $taskClient = new TaskClient();
    $taskClient->rootUri = $conductorRootUri;
    
    $builder = new WorkflowTaskCoordinatorBuilder();
    $builder->withThreadCount($threadCount);
    $builder->withTaskClient($taskClient);
    $builder->withWorkers($workerList);
    
    $coordinator = $builder->build();
    $coordinator->init();
    

The Versions

18/05 2018

dev-master

9999999-dev

php client for netflix conductor

  Sources   Download

The Requires

  • php >=7.2

 

The Development Requires

by thuyenlv

conductor

18/05 2018

1.0.1

1.0.1.0

php client for netflix conductor

  Sources   Download

The Requires

  • php >=7.2

 

The Development Requires

by thuyenlv

conductor

02/05 2018

1.0.0

1.0.0.0

php client for netflix conductor

  Sources   Download

2018

The Requires

  • php >=7.2

 

The Development Requires

by thuyenlv

conductor