@@ -13,22 +13,31 @@ class Client
13
13
protected array $ workerInfo ;
14
14
protected LoggerInterface $ logger ;
15
15
protected TcpClient $ tcpClient ;
16
+ protected string $ workerId ;
16
17
17
18
public function __construct (
18
19
Level $ logLevel = Level::Info,
19
20
string $ logDestination = 'php://stderr ' ,
20
21
?LoggerInterface $ logger = null ,
22
+ string $ hostname = 'tcp://localhost ' ,
23
+ int |string $ port = 7419 ,
24
+ string $ password = '' ,
21
25
)
22
26
{
23
27
$ this ->logger = $ logger ?: self ::makeLogger ($ logLevel , $ logDestination );
28
+ $ this ->workerId = bin2hex (random_bytes (12 ));
24
29
$ this ->workerInfo = [
25
30
"hostname " => gethostname (),
26
- "wid " => " test-worker-1 " ,
31
+ "wid " => $ this -> workerId ,
27
32
"pid " => getmypid (),
28
33
"labels " => [],
29
34
];
30
35
$ this ->tcpClient = self ::makeTcpClient (
31
- $ this ->logger , $ this ->workerInfo , hostname: 'tcp://dreamatorium.local '
36
+ logger: $ this ->logger ,
37
+ workerInfo: $ this ->workerInfo ,
38
+ hostname: $ hostname ,
39
+ port: $ port ,
40
+ password: $ password ,
32
41
);
33
42
}
34
43
@@ -61,13 +70,14 @@ public function fetch(string ...$queues): array|null
61
70
return $ this ->tcpClient ->readLine (skipLines: 1 );
62
71
}
63
72
64
- public static function makeTcpClient ($ workerInfo , $ logger , $ hostname ): TcpClient
73
+ public static function makeTcpClient (... $ args ): TcpClient
65
74
{
66
- return new TcpClient ($ workerInfo , $ logger , $ hostname );
75
+ return new TcpClient (... $ args );
67
76
}
68
77
69
78
public static function makeLogger (
70
- Level $ logLevel = Level::Info, string $ logDestination = 'php://stderr ' ): LoggerInterface
79
+ Level $ logLevel = Level::Info, string $ logDestination = 'php://stderr ' )
80
+ : LoggerInterface
71
81
{
72
82
return new Logger (
73
83
name: 'faktory-php ' ,
0 commit comments