Skip to content

Commit

Permalink
% update CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondDantes committed Oct 13, 2024
1 parent c13838d commit 7cff92e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [1.0.1] - 2024-10-13 [Release]

### Added

- Added `WorkerPoolInterface::setPoolContext()` + `WorkerInterface::getPoolContext()` methods.
Each `Worker` can receive a shared application context during startup,
which is set using the `setPoolContext()` method before calling the `WorkerPoolInterface::start()` method.


## [1.0.0] - 2024-07-13 [Release]

### Fixed
Expand Down
15 changes: 10 additions & 5 deletions src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class Worker implements WorkerInterface
/** @var ConcurrentIterator<TReceive> */
protected readonly ConcurrentIterator $iterator;

protected readonly array $context;
/**
* Shared context between all workers.
*
* @var array $poolContext
*/
protected readonly array $poolContext;

private LoggerInterface $logger;
private WorkersStorageInterface $workersStorage;
Expand Down Expand Up @@ -83,15 +88,15 @@ public function __construct(
private readonly array $groupsScheme,
string $workersStorageClass,
?LoggerInterface $logger = null,
array $context = []
array $poolContext = []
) {
$this->queue = new Queue();
$this->iterator = $this->queue->iterate();
$this->mainCancellation = new DeferredCancellation;
$this->workerFuture = new DeferredFuture;

$this->eventEmitter = new WorkerEventEmitter;
$this->context = $context;
$this->poolContext = $poolContext;

if(\class_exists($workersStorageClass) === false) {
throw new \RuntimeException('Invalid storage class provided. Expected ' . WorkersStorageInterface::class . ' implementation');
Expand Down Expand Up @@ -179,9 +184,9 @@ public function getWorkerType(): WorkerTypeEnum
}

#[\Override]
public function getWorkerContext(): array
public function getPoolContext(): array
{
return $this->context;
return $this->poolContext;
}

public function getWorkerEventEmitter(): WorkerEventEmitterInterface
Expand Down
8 changes: 7 additions & 1 deletion src/Worker/WorkerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public function getWorkerId(): int;
public function getWorkerGroup(): WorkerGroup;
public function getWorkerGroupId(): int;
public function getWorkerType(): WorkerTypeEnum;
public function getWorkerContext(): array;

/**
* Returns the context of the worker pool.
*
* @return array
*/
public function getPoolContext(): array;

public function getAbortCancellation(): Cancellation;

Expand Down

0 comments on commit 7cff92e

Please sign in to comment.