Skip to content

Commit d7ad1ed

Browse files
committed
Rework config
1 parent c519a72 commit d7ad1ed

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Diff for: src/Client.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,31 @@ class Client
1313
protected array $workerInfo;
1414
protected LoggerInterface $logger;
1515
protected TcpClient $tcpClient;
16+
protected string $workerId;
1617

1718
public function __construct(
1819
Level $logLevel = Level::Info,
1920
string $logDestination = 'php://stderr',
2021
?LoggerInterface $logger = null,
22+
string $hostname = 'tcp://localhost',
23+
int|string $port = 7419,
24+
string $password = '',
2125
)
2226
{
2327
$this->logger = $logger ?: self::makeLogger($logLevel, $logDestination);
28+
$this->workerId = bin2hex(random_bytes(12));
2429
$this->workerInfo = [
2530
"hostname" => gethostname(),
26-
"wid" => "test-worker-1",
31+
"wid" => $this->workerId,
2732
"pid" => getmypid(),
2833
"labels" => [],
2934
];
3035
$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,
3241
);
3342
}
3443

@@ -61,13 +70,14 @@ public function fetch(string ...$queues): array|null
6170
return $this->tcpClient->readLine(skipLines: 1);
6271
}
6372

64-
public static function makeTcpClient($workerInfo, $logger, $hostname): TcpClient
73+
public static function makeTcpClient(...$args): TcpClient
6574
{
66-
return new TcpClient($workerInfo, $logger, $hostname);
75+
return new TcpClient(...$args);
6776
}
6877

6978
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
7181
{
7282
return new Logger(
7383
name: 'faktory-php',

Diff for: src/TcpClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
protected LoggerInterface $logger,
2727
protected array $workerInfo = [],
2828
protected string $hostname = 'tcp://localhost',
29-
protected int $port = 7419,
29+
protected int|string $port = 7419,
3030
protected string $password = '',
3131
) {
3232
$this->responseParser = (new ProtocolFactory())->createResponseParser();

Diff for: tests/client_test.php

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ function client($mockTcpClient) {
2222
]);
2323
expect();
2424
})->skip();
25+
26+
it('can push jobs in bulk', function () {
27+
})->skip();

0 commit comments

Comments
 (0)