Skip to content

Commit

Permalink
Update: worker name can be initialized at registration time
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Jan 17, 2025
1 parent f786ec5 commit ef8c780
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Worker/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ class Manager
*/
public function addWorker(Worker $worker): void
{
if (isset($this->workers[$worker->getName()])) {
Output::warning('Worker name already exists');
$worker->register($this);
$workerName = $worker->getName();
if (isset($this->workers[$workerName])) {
Output::warning("Worker {$workerName} already exists");
return;
}
$this->workers[$worker->getName()] = $worker;
$this->workers[$workerName] = $worker;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ abstract class Worker
/**
* @var string
*/
protected string $name = 'worker';
protected string $name;

/**
* @var array
*/
private array $queue = [];

/**
*
*/
public function __construct()
{
$this->name = static::class;
$this->count = 1;
}

/**
* Send instructions to the specified Worker
*
Expand Down

0 comments on commit ef8c780

Please sign in to comment.