Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Library/Client/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace Vpg\Disturb\Client;

use \Phalcon\Mvc\User\Component;
use \Vpg\Disturb\Message;
use \Vpg\Disturb\Workflow\WorkflowConfigDtoFactory;
use Vpg\Disturb\Context;

include realpath(__DIR__ . '/../../bin/configCommand.php');

/**
* Class Disturb Client Command
*
* @package Disturb\Client
* @author Maxime BRENGUIER <mbrenguier@voyageprive.com>
* @license https://github.com/vpg/disturb/blob/master/LICENSE MIT Licence
*/
class Command extends Component
{
/**
* Start workflow by sending a message in related topic
*
* @param String $workflowProcessId Workflow id
* @param Array $payloadHash List of params
* @param String $brokers broker list
* @param String $topicName topic name
*
* @return void
*/
public static function start(string $workflowProcessId, array $payloadHash, string $brokers, string $topicName)
{
$messageHash = [
'id' => $workflowProcessId,
'type' => Message\MessageDto::TYPE_WF_CTRL,
'action' => 'start',
'payload' => $payloadHash
];
//send message with givens params
$kafkaProducer = new \RdKafka\Producer();
$kafkaProducer->addBrokers($brokers);
$kafkaTopic = $kafkaProducer->newTopic($topicName);
$kafkaTopic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($messageHash));
}

/**
* Get status for a specified workflow process id
*
* @param string $workflowProcessId workflow process id
* @param string $workflowConfigFilePath workflow config file path
*
* @return string
*/
public static function getStatus(string $workflowProcessId, string $workflowConfigFilePath)
{
$workflowConfigDto = WorkflowConfigDtoFactory::get($workflowConfigFilePath);
$contextStorage = new Context\ContextStorageService($workflowConfigDto);
return $contextStorage->get($workflowProcessId)->getWorkflowStatus();
}

/**
* Get context for a specified workflow process id
*
* @param string $workflowProcessId workflow process id
* @param string $workflowConfigFilePath workflow config file path
*
* @return array
*/
public static function getContext(string $workflowProcessId, string $workflowConfigFilePath)
{
$workflowConfigDto = WorkflowConfigDtoFactory::get($workflowConfigFilePath);
$contextStorage = new Context\ContextStorageService($workflowConfigDto);
return $contextStorage->get($workflowProcessId)->getStepResultData();
}
}
4 changes: 3 additions & 1 deletion Library/Workflow/ManagerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ public function getNextStepList(string $workflowProcessId) : array
*/
public function hasNextStep(string $workflowProcessId) : bool
{
$this->di->get('logr')->debug(json_encode(func_get_args()));
$this->di->get('logr')->info(json_encode(func_get_args()));
$contextDto = $this->di->get('contextStorage')->get($workflowProcessId);

$nextStepPos = $contextDto->getWorkflowCurrentPosition() + 1;

return !empty($this->workflowConfig->getStepList()[$nextStepPos]);
}

Expand Down
4 changes: 3 additions & 1 deletion Library/Workflow/ManagerWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ protected function processMessage(Message\MessageDto $messageDto)
break;
case ManagerService::STATUS_SUCCESS:
// go to next step if there is a next step and while the current step has no job
while ($hasNext = $this->workflowManagerService->hasNextStep($messageDto->getId()) &&
while (($hasNext = $this->workflowManagerService->hasNextStep($messageDto->getId())) &&
false == $this->runNextStep($messageDto->getId())
) {
$this->getDI()->get('logr')->warning("Current step skipped");
};



if (!$hasNext) {
$this->workflowManagerService->finalize(
$messageDto->getId(),
Expand Down
22 changes: 22 additions & 0 deletions bin/configCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Register the autoloader and tell it to register the tasks directory
*/
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
[
'Vpg\Disturb' => realpath(__DIR__ . '/../Library/')
],
true
);

$loader->registerFiles([
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php'
]);
$loader->register();

require_once(__DIR__ . '/../Library/Core/DI.php');

$di->setShared('loader', $loader);