Repository navigation
Decouple application boot from queue broker availability #121
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b2b14f
fix(queue): decouple app boot from broker availability
amasiye 6ea4d34
Merge remote-tracking branch 'origin/main' into develop
amasiye 4ff6f30
test(queue): cover invalid named connections
amasiye 5eab99b
ci: retrigger pull request build
amasiye 02f4a3e
test(queue): verify factory injection in module graph
amasiye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # AssegaiPHP Core 0.10.1 | ||
|
|
||
| Core 0.10.1 decouples application bootstrap from queue backend availability. | ||
|
|
||
| ## What changed | ||
|
|
||
| - adds an injectable `QueueFactory` for resolving configured `driver.connection` queue names programmatically | ||
| - keeps one queue instance per named connection for the lifetime of the application graph | ||
| - resolves `#[InjectQueue]` through the container's parameter-resolver seam instead of performing work inside the attribute constructor | ||
| - keeps queue attributes as metadata and delegates driver validation and creation to the named factory | ||
| - retains the application queue factory across request-scope refreshes in reusable runtimes | ||
| - documents that queue drivers must defer broker I/O until an operation needs the transport | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - requires `assegaiphp/common:^0.10.0` | ||
| - lazy broker availability requires `assegaiphp/rabbitmq:^1.1.2` or `assegaiphp/beanstalkd:^1.1.2` | ||
| - existing `#[InjectQueue('driver.connection')] QueueInterface` constructor injection remains source compatible | ||
|
|
||
| ## Upgrade notes | ||
|
|
||
| Applications can continue using `#[InjectQueue]` without changes. Code that manually reads `queues.php` and calls a driver's static `create()` method can instead inject `QueueFactory` and call `connection()`. | ||
|
|
||
| Queue connection failures now occur at the first broker-backed operation rather than while the application graph is constructed. Handle enqueue failures at the domain boundary where the application can decide whether to return an error, persist an outbox record, or apply another explicit fallback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| namespace Assegai\Core\Queues; | ||
|
|
||
| use Assegai\Common\Interfaces\Queues\QueueInterface; | ||
| use Assegai\Core\Attributes\Injectable; | ||
| use InvalidArgumentException; | ||
|
|
||
| #[Injectable] | ||
| final class QueueFactory | ||
| { | ||
| /** @var array<string, QueueInterface<object>> */ | ||
| private array $connections = []; | ||
|
|
||
| /** | ||
| * Resolves one configured queue for the lifetime of the application graph. | ||
| * | ||
| * Driver creation must remain configuration-only. Transport implementations | ||
| * establish their broker connection when an operation first needs it. | ||
| * | ||
| * @return QueueInterface<object> | ||
| */ | ||
| public function connection(string $path): QueueInterface | ||
| { | ||
| $path = trim($path); | ||
|
|
||
| if (isset($this->connections[$path])) { | ||
| return $this->connections[$path]; | ||
| } | ||
|
|
||
| [$driver, $name] = explode('.', $path, 2) + [null, null]; | ||
|
|
||
| if (!is_string($driver) || $driver === '' || !is_string($name) || $name === '') { | ||
| throw new InvalidArgumentException("Invalid queue path '$path'. Expected format: 'driver.name'."); | ||
| } | ||
|
|
||
| $queueConfig = config("queues.connections.$path"); | ||
|
|
||
| if (!is_array($queueConfig)) { | ||
| throw new InvalidArgumentException("Queue configuration for '$path' not found."); | ||
| } | ||
|
|
||
| $queueConfig['name'] ??= $name; | ||
| $driverClass = config("queues.drivers.$driver"); | ||
|
|
||
| if (!is_string($driverClass) || !class_exists($driverClass)) { | ||
| throw new InvalidArgumentException("Queue driver '$driver' is not configured or does not exist."); | ||
| } | ||
|
|
||
| if (!is_subclass_of($driverClass, QueueInterface::class)) { | ||
| throw new InvalidArgumentException("Queue driver '$driver' must implement the QueueInterface."); | ||
| } | ||
|
|
||
| return $this->connections[$path] = $driverClass::create($queueConfig); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| namespace Assegai\Core\Queues; | ||
|
|
||
| use Assegai\Core\Injector; | ||
| use Assegai\Core\Interfaces\ParameterResolverInterface; | ||
| use Assegai\Core\Queues\Attributes\InjectQueue; | ||
| use ReflectionParameter; | ||
|
|
||
| final readonly class QueueParameterResolver implements ParameterResolverInterface | ||
| { | ||
| public function __construct(private QueueFactory $factory) | ||
| { | ||
| } | ||
|
|
||
| public function supports(ReflectionParameter $parameter, Injector $injector): bool | ||
| { | ||
| return $parameter->getAttributes(InjectQueue::class) !== []; | ||
| } | ||
|
|
||
| public function resolve(ReflectionParameter $parameter, Injector $injector): mixed | ||
| { | ||
| /** @var InjectQueue $attribute */ | ||
| $attribute = $parameter->getAttributes(InjectQueue::class)[0]->newInstance(); | ||
|
|
||
| return $this->factory->connection($attribute->path); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.