Skip to content

Commit

Permalink
Improved the state management
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Nov 3, 2023
1 parent 21b6edd commit 7270999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ final class State implements StateInterface

public function __construct(
private readonly StateManager $manager,
private readonly string $jobCode,
private readonly string $stepCode,
private readonly string $stepLabel,
) {
}

Expand Down Expand Up @@ -55,8 +55,8 @@ public function teardown(): void
public function toArray(): array

Check failure on line 55 in src/State.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Flow\RabbitMQ\State::toArray() return type has no value type specified in iterable type array.
{
return [
'code' => $this->stepCode,
'label' => $this->stepLabel ?: $this->stepCode,
'jobCode' => $this->jobCode,
'stepCode' => $this->stepCode,
'metrics' => iterator_to_array($this->walkMetrics()),
];
}
Expand Down
9 changes: 6 additions & 3 deletions src/StateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ public static function withAuthentication(


public function stepState(
string $jobCode,
string $stepCode,
string $stepLabel,
): State {
return $this->steps[] = new State($this, $stepCode, $stepLabel);
$this->steps[] = $state = new State($this, $jobCode, $stepCode);

return $state;
}

public function trySend($count): void

Check failure on line 93 in src/StateManager.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Flow\RabbitMQ\StateManager::trySend() has parameter $count with no type specified.
Expand Down Expand Up @@ -118,11 +120,12 @@ private function sendUpdate(): void
$this->channel->publish(
json_encode([
'messageNumber' => ++$this->messageCount,
'id' => Uuid::uuid4(),
'execution' => getenv('EXECUTION_ID'),
'date' => ['date' => $date->format('c'), 'tz' => $date->getTimezone()->getName()],
'stepsUpdates' => array_map(fn (State $step) => $step->toArray(), $this->steps),
], \JSON_THROW_ON_ERROR),
[
'type' => 'update',
'content-type' => 'application/json',
],
$this->exchange,
Expand Down

0 comments on commit 7270999

Please sign in to comment.