public function testDel() { $redis = $this->getRedisMemoryPool(); $jail = JailedMemoryPool::jail($redis, 'test'); $redis->set('hello', 'world'); $this->assertEquals('world', $jail->get('hello', 'fake')); $this->assertEquals('world', $redis->get('test:hello', 'fake')); $jail->delete('hello'); $this->assertEquals('fake', $jail->get('hello', 'fake')); $this->assertEquals('fake', $redis->get('test:hello', 'fake')); }
/** * Execute a task * * @param TaskSchema $task * @param WorkEvent $event */ protected function executeTask(TaskSchema $task, WorkEvent $event) { $memory_pool = $this->getWorkflow()->getJailMemoryPool() ? JailedMemoryPool::jail($this->getMemoryPool(), ':' . $event->getExecutionId()) : $this->getMemoryPool(); $class = $task->getClass(); /** @var TaskInterface $obj */ $obj = new $class($memory_pool, $event->getInput(), $this->getAuxPayload()); if (!$obj instanceof TaskInterface) { throw new \DomainException("Class for task " . $task->getActivityName() . " is not a TaskInterface"); } $obj->execute($event); }
/** * Process the decision event, generating a decision response (included in the DecisionEvent) * * @param DecisionEvent $event */ public function processDecisionEvent(DecisionEvent $event) { $history = $event->getHistory(); $decision = $event->getDecision(); $tasks = $this->getWorkflow()->getTasks(); // Create a memory pool jailed to this execution $memory_pool = $this->getWorkflow()->getJailMemoryPool() ? JailedMemoryPool::jail($this->getMemoryPool(), ':' . $event->getExecutionId()) : $this->getMemoryPool(); // Check if we need to execute any task events /** @var WorkflowHistoryItem $history_item */ foreach ($history as $history_item) { $id = $history_item->getEventId(); if ($history_item->getState() == HistoryItemState::COMPLETED()) { if ($memory_pool->get('history:' . $id . ':completed') === null) { $this->runTaskDecider($history_item, $decision, $memory_pool); $memory_pool->set('history:' . $id . ':completed', 1); } } } // Check if we need to fail if ($this->getFailOnActivityFailure() && $history->hasActivityFailure() || $history->hasWorkflowFailed()) { $decision->setWorkflowResult(WorkflowResult::FAIL()); $decision->setReason(implode(", ", $history->getErrorMessages())); return; } // Check if we need to schedule $parser = new InputParser($history, $memory_pool); $scheduler = new Scheduler($history, $memory_pool); foreach ($tasks as $task) { if ($scheduler->canScheduleTask($task)) { $decision->scheduledTask($parser->compileTaskInput($task)); } } // Check if we need to complete if (count($decision->getScheduledTasks()) == 0 && !$scheduler->haveOpenActivities()) { $decision->setWorkflowResult(WorkflowResult::COMPLETE()); } }
/** * Get a (jailed) memory pool matching this workflow execution * * @param WorkflowInterface $workflow * @param string $execution_id * @return MemoryPoolInterface */ protected function getMemoryPoolForWorkflow(WorkflowInterface $workflow, $execution_id) { return $workflow->getJailMemoryPool() ? JailedMemoryPool::jail($this->getMemoryPool(), ':' . $execution_id) : $this->getMemoryPool(); }