-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add callback to check how many workers are available #34
Changes from 2 commits
35697bf
3f8f866
680ec4f
2cd654f
6791dc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,26 @@ public function addWorker(string $plugin): void | |||||||||||||||||||||||||||||||||||||||||||||
$this->rpc->call('informer.AddWorker', $plugin); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* Get the worker count for a pool. | ||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||
* @param non-empty-string $plugin | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
public function countWorkers(string $plugin): int | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
return count($this->getWorkers($plugin)); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* Get the info about running workers for a pool. | ||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||
* @param non-empty-string $plugin | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
public function getWorkers(string $plugin): array | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
return $this->rpc->call('informer.Workers', $plugin)['workers']; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - return $this->rpc->call('informer.Workers', $plugin)['workers'];
+ $response = $this->rpc->call('informer.Workers', $plugin);
+ if (!isset($response['workers'])) {
+ throw new \RuntimeException("Unexpected response structure from informer.Workers");
+ }
+ return $response['workers']; Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||
* Remove worker from the pool. | ||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,10 +35,24 @@ public function testAddWorker(): void | |
$this->workerPool->addWorker('test'); | ||
} | ||
|
||
public function testCountWorkers(): void | ||
{ | ||
$this->rpc->expects($this->once())->method('call')->with('informer.Workers', 'test')->willReturn(['workers' => []]); | ||
|
||
$this->workerPool->countWorkers('test'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
public function testGetWorkers(): void | ||
{ | ||
$this->rpc->expects($this->once())->method('call')->with('informer.Workers', 'test')->willReturn(['workers' => []]); | ||
|
||
$this->workerPool->getWorkers('test'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
public function testRemoveWorker(): void | ||
{ | ||
$this->rpc->expects($this->once())->method('call')->with('informer.RemoveWorker', 'test'); | ||
|
||
$this->workerPool->removeWorker('test'); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of
countWorkers
directly relies on thegetWorkers
method to determine the count. This approach is straightforward and leverages existing functionality for consistency. However, consider the performance implications ifgetWorkers
performs heavy operations or fetches a large amount of data. In such cases, a more direct approach to counting, if available through the underlying RPC mechanism, might be more efficient.