@@ -13,6 +13,7 @@ final class State implements StateInterface
1313
1414 public function __construct (
1515 private Client $ connection ,
16+ private string $ pipelineId ,
1617 private string $ stepCode ,
1718 private string $ stepLabel ,
1819 private string $ topic ,
@@ -22,6 +23,7 @@ public function __construct(
2223 }
2324
2425 public static function withoutAuthentication (
26+ string $ pipelineId ,
2527 string $ stepCode ,
2628 string $ stepLabel ,
2729 string $ host ,
@@ -39,10 +41,11 @@ public static function withoutAuthentication(
3941 ]);
4042 $ connection ->connect ();
4143
42- return new self ($ connection , stepCode: $ stepCode , stepLabel: $ stepLabel , topic: $ topic , exchange: $ exchange );
44+ return new self ($ connection , pipelineId: $ pipelineId , stepCode: $ stepCode , stepLabel: $ stepLabel , topic: $ topic , exchange: $ exchange );
4345 }
4446
4547 public static function withAuthentication (
48+ string $ pipelineId ,
4649 string $ stepCode ,
4750 string $ stepLabel ,
4851 string $ host ,
@@ -62,14 +65,15 @@ public static function withAuthentication(
6265 ]);
6366 $ connection ->connect ();
6467
65- return new self ($ connection , stepCode: $ stepCode , stepLabel: $ stepLabel , topic: $ topic , exchange: $ exchange );
68+ return new self ($ connection , pipelineId: $ pipelineId , stepCode: $ stepCode , stepLabel: $ stepLabel , topic: $ topic , exchange: $ exchange );
6669 }
6770
6871 public function initialize (int $ start = 0 ): void
6972 {
7073 $ this ->metrics = [
7174 'accept ' => 0 ,
7275 'reject ' => 0 ,
76+ 'error ' => 0 ,
7377 ];
7478
7579 $ this ->channel ->queueDeclare (
@@ -97,7 +101,9 @@ public function reject(int $step = 1): void
97101
98102 public function error (int $ step = 1 ): void
99103 {
100- // Not implemented yet
104+ $ this ->metrics ['error ' ] += $ step ;
105+
106+ $ this ->sendMessage ('error ' );
101107 }
102108
103109 public function teardown (): void
@@ -112,7 +118,7 @@ private function sendMessage(string $metricCode): void
112118
113119 $ this ->channel ->publish (
114120 \json_encode ([
115- 'id ' => '' ,
121+ 'id ' => $ this -> pipelineId ,
116122 'date ' => ['date ' => $ date ->format ('c ' ), 'tz ' => $ date ->getTimezone ()->getName ()],
117123 'stepsUpdates ' => [
118124 [
@@ -121,7 +127,7 @@ private function sendMessage(string $metricCode): void
121127 'metrics ' => [
122128 [
123129 'code ' => $ metricCode ,
124- 'increment ' => $ step
130+ 'increment ' => $ this -> metrics [ $ metricCode ]
125131 ]
126132 ]
127133 ]
0 commit comments