Skip to content

Commit 4485c68

Browse files
committed
Minor fixes
1 parent 72a674d commit 4485c68

52 files changed

Lines changed: 167 additions & 147 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ change to start working with the queue:
4343
## Differences to yii2-queue
4444

4545
If you have experience with `yiisoft/yii2-queue`, you will find out that this package is similar.
46-
Though, there are some key differences which are described in the "[migrating from yii2-queue](docs/guide/migrating-from-yii2-queue.md)" article.
46+
Though, there are some key differences that are described in the "[migrating from yii2-queue](docs/guide/migrating-from-yii2-queue.md)"
47+
article.
4748

4849
## General usage
4950

5051
Each queue task consists of two parts:
5152

5253
1. A message is a class implementing `MessageInterface`. For simple cases you can use the default implementation,
53-
`Yiisoft\Queue\Message\Message`. For more complex cases you should implement the interface by your own.
54+
`Yiisoft\Queue\Message\Message`. For more complex cases, you should implement the interface by your own.
5455
2. A message handler is a callable called by a `Yiisoft\Queue\Worker\Worker`. The handler handles each queue message.
5556

5657
For example, if you need to download and save a file, your message creation may look like the following:
@@ -103,7 +104,7 @@ $worker = new \Yiisoft\Queue\Worker\Worker(
103104
);
104105
```
105106

106-
There is the way to run all the messages that are already in the queue, and then exit:
107+
There is a way to run all the messages that are already in the queue, and then exit:
107108

108109
```php
109110
$queue->run(); // this will execute all the existing messages
@@ -147,7 +148,7 @@ To use a custom handler name before message push, you can pass it as the first a
147148
new Message('handler-name', $data);
148149
```
149150

150-
To use a custom handler name on message consume, you should configure handler mapping for the `Worker` class:
151+
To use a custom handler name on message consumption, you should configure handler mapping for the `Worker` class:
151152
```php
152153
$worker = new \Yiisoft\Queue\Worker\Worker(
153154
['handler-name' => FooHandler::class],
@@ -175,7 +176,7 @@ Out of the box, there are four implementations of the `QueueProviderInterface`:
175176

176177
### `AdapterFactoryQueueProvider`
177178

178-
Provider based on definition of channel-specific adapters. Definitions are passed in
179+
Provider based on the definition of channel-specific adapters. Definitions are passed in
179180
the `$definitions` constructor parameter of the factory, where keys are channel names and values are definitions
180181
for the [`Yiisoft\Factory\Factory`](https://github.com/yiisoft/factory). Below are some examples:
181182

@@ -192,7 +193,7 @@ use Yiisoft\Queue\Adapter\SynchronousAdapter;
192193
]
193194
```
194195

195-
For more information about a definition formats available see the [factory](https://github.com/yiisoft/factory) documentation.
196+
For more information about the definition formats available, see the [factory](https://github.com/yiisoft/factory) documentation.
196197

197198
### `PrototypeQueueProvider`
198199

@@ -226,14 +227,14 @@ yii queue:listen
226227

227228
See the documentation for more details about adapter specific console commands and their options.
228229

229-
The component also has the ability to track the status of a job which was pushed into queue.
230+
The component can also track the status of a job which was pushed into queue.
230231

231-
For more details see [the guide](docs/guide/en/README.md).
232+
For more details, see [the guide](docs/guide/en/README.md).
232233

233234
## Middleware pipelines
234235

235236
Any message pushed to a queue or consumed from it passes through two different middleware pipelines: one pipeline
236-
on message push and another - on message consume. The process is the same as for the HTTP request, but it is executed
237+
on message push and another - on a message consume. The process is the same as for the HTTP request, but it is executed
237238
twice for a queue message. That means you can add extra functionality on message pushing and consuming with configuration
238239
of the two classes: `PushMiddlewareDispatcher` and `ConsumeMiddlewareDispatcher` respectively.
239240

@@ -262,13 +263,13 @@ graph LR
262263
ConsumeMiddleware1[$middleware1] -.-> EndConsume((End))
263264
```
264265

265-
### Push pipeline
266+
### Push a pipeline
266267

267268
When you push a message, you can use middlewares to modify both message and queue adapter.
268269
With message modification you can add extra data, obfuscate data, collect metrics, etc.
269-
With queue adapter modification you can redirect message to another queue, delay message consuming, and so on.
270+
With queue adapter modification you can redirect the message to another queue, delay message consuming, and so on.
270271

271-
To use this feature you have to create a middleware class, which implements `MiddlewarePushInterface`, and
272+
To use this feature, you have to create a middleware class, which implements `MiddlewarePushInterface`, and
272273
return a modified `PushRequest` object from the `processPush` method:
273274

274275
```php
@@ -297,16 +298,16 @@ along with them.
297298

298299
### Consume pipeline
299300

300-
You can set a middleware pipeline for a message when it will be consumed from a queue server. This is useful to collect metrics, modify message data, etc. In pair with a Push middleware you can deduplicate messages in the queue, calculate time from push to consume, handle errors (push to a queue again, redirect failed message to another queue, send a notification, etc.). Unless Push pipeline, you have only one place to define the middleware stack: in the `ConsumeMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-consume` key of the `yiisoft/queue` array in the `params`.
301+
You can set a middleware pipeline for a message when it will be consumed from a queue server. This is useful to collect metrics, modify message data, etc. In a pair with a Push middleware you can deduplicate messages in the queue, calculate time from push to consume, handle errors (push to a queue again, redirect failed message to another queue, send a notification, etc.). Except push pipeline, you have only one place to define the middleware stack: in the `ConsumeMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-consume` key of the `yiisoft/queue` array in the `params`.
301302

302303
### Error handling pipeline
303304

304-
Often when some job is failing, we want to retry its execution a couple more times or redirect it to another queue channel. This can be done in `yiisoft/queue` with Failure middleware pipeline. They are triggered each time message processing via the Consume middleware pipeline is interrupted with any `Throwable`. The key differences from the previous two pipelines:
305+
Often when some job is failing, we want to retry its execution a couple more times or redirect it to another queue channel. This can be done in `yiisoft/queue` with a Failure middleware pipeline. They are triggered each time message processing via the Consume middleware pipeline is interrupted with any `Throwable`. The key differences from the previous two pipelines:
305306

306307
- You should set up the middleware pipeline separately for each queue channel. That means, the format should be `['channel-name' => [FooMiddleware::class]]` instead of `[FooMiddleware::class]`, like for the other two pipelines. There is also a default key, which will be used for those channels without their own one: `FailureMiddlewareDispatcher::DEFAULT_PIPELINE`.
307308
- The last middleware will throw the exception, which will come with the `FailureHandlingRequest` object. If you don't want the exception to be thrown, your middlewares should `return` a request without calling `$handler->handleFailure()`.
308309

309-
You can declare error handling middleware pipeline in the `FailureMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-fail` key of the `yiisoft/queue` array in the `params`.
310+
You can declare error handling a middleware pipeline in the `FailureMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](yiisoft/config), you can add middleware to the `middlewares-fail` key of the `yiisoft/queue` array in the `params`.
310311

311312
See [error handling docs](docs/guide/error-handling.md) for details.
312313

docs/guide/en/error-handling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Often when some message handling is failing, we want to retry its execution a co
44

55
## Configuration
66

7-
Here below is configuration via `yiisoft/config`. If you don't use it - you should add middleware definition list (in the `middlewares-fail` key here) to the `FailureMiddlewareDispatcher` by your own.
7+
Here below is configuration via `yiisoft/config`. If you don't use it, you should add a middleware definition list (in the `middlewares-fail` key here) to the `FailureMiddlewareDispatcher` by your own.
88

99
Configuration should be passed to the `yiisoft/queue.fail-strategy-pipelines` key of the `params` config to work with the `yiisoft/config`. You can define different failure handling pipelines for each queue channel. Let's see and describe an example:
1010

@@ -39,10 +39,10 @@ Configuration should be passed to the `yiisoft/queue.fail-strategy-pipelines` ke
3939
]
4040
```
4141

42-
Keys here except `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` are queue channel names, and values are lists of `FailureMiddlewareInterface` definitions. `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` defines a default pipeline to apply to channels without explicitly defined failure strategy pipeline. Each middleware definition must be one of:
42+
Keys here except `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` are queue channel names, and values are lists of `FailureMiddlewareInterface` definitions. `FailureMiddlewareDispatcher::DEFAULT_PIPELINE` defines a default pipeline to apply to channels without an explicitly defined failure strategy pipeline. Each middleware definition must be one of:
4343
- A ready-to-use `MiddlewareFailureInterface` object like `new FooMiddleware()`.
4444
- A valid definition for the [yiisoft/definitions](https://github.com/yiisoft/definitions). It must describe an object, implementing the `MiddlewareFailureInterface`.
45-
- A callable: `fn() => // do stuff`, `$object->foo(...)`, etc. It will be executed through the `yiisoft/injector`, so all the dependencies of your callable will be resolved. You can also define a "callable-looking" array, where object will be instantiated with a DI container: `[FooMiddleware::class, 'handle']`.
45+
- A callable: `fn() => // do stuff`, `$object->foo(...)`, etc. It will be executed through the `yiisoft/injector`, so all the dependencies of your callable will be resolved. You can also define a "callable-looking" array, where an object will be instantiated with a DI container: `[FooMiddleware::class, 'handle']`.
4646
- A string for your DI container to resolve the middleware, e.g. `FooMiddleware::class`.
4747

4848
In the example above failures will be handled this way (look the concrete middleware description below):

docs/guide/en/migrating-from-yii2-queue.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Migrating from yii2-queue
22

3-
This package is similar to [yiisoft/yii2-queue] but with improved design and code style. The new package less coupled
3+
This package is similar to [yiisoft/yii2-queue] but with improved design and code style. The new package is less coupled
44
and more structured than the old one allowing better maintenance.
55

66
## Adapters
77

8-
- Individual adapters are now separate packages. This means each adapter must be `require`d with composer in order to
8+
- Individual adapters are now separate packages. This means each adapter must be `require`d with composer to
99
be available in your application.
1010
- Adapter may be any class which implements `AdapterInterface`. This means you can replace one adapter with another without
1111
changing any code in your app. For example, you can use `db` adapter in development while using `amqp` in production,
@@ -15,11 +15,11 @@ and more structured than the old one allowing better maintenance.
1515
## Jobs (Messages and Handlers)
1616

1717
There was a concept in [yiisoft/yii2-queue] called `Job`: you had to push it to the queue, and it was executed after
18-
being consumed. In the new package it is divided into two different concepts: a message and a handler.
18+
being consumed. In the new package, it is divided into two different concepts: a message and a handler.
1919

20-
- A `Message` is a class implementing `MessageInterface`. It contains 2 types of data:
21-
- Name. Worker uses it to find the right handler for a message.
22-
- Data. Any serializable data which should be used by the message handler.
20+
- A `Message` is a class implementing `MessageInterface`. It contains two types of data:
21+
- Name. The worker uses it to find the right handler for a message.
22+
- Data. Any serializable data that should be used by the message handler.
2323

2424
All the message data is fully serializable (that means message `data` must be serializable too). It allows you to
2525
freely choose where and how to send and process jobs. Both can be implemented in a single application, or

docs/guide/en/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ See also the documentation for concrete adapters ([synchronous adapter](adapter-
2626
## Usage
2727

2828
Each job sent to the queue should be defined as a separate class.
29-
For example, if you need to download and save a file the class may look like the following:
29+
For example, if you need to download and save a file, the class may look like the following:
3030

3131
```php
3232
$data = [
@@ -54,7 +54,7 @@ To push a job into the queue that should run after 5 minutes:
5454
## Queue handling
5555

5656
The exact way how a job is executed depends on the adapter used. Most adapters can be run using
57-
console commands, which the component registers in your application. For more details check the respective
57+
console commands, which the component registers in your application. For more details, check the respective
5858
adapter documentation.
5959

6060

@@ -79,7 +79,7 @@ $status->isDone($id);
7979

8080
## Limitations
8181

82-
When using queues it is important to remember that tasks are put into and obtained from the queue in separate
82+
When using queues, it is important to remember that tasks are put into and obtained from the queue in separate
8383
processes. Therefore, avoid external dependencies when executing a task if you're not sure if they are available in
8484
the environment where the worker does its job.
8585

docs/guide/en/worker.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration
22

3-
To use a worker, you should resolve its dependencies (e.g. through DI container) and define handlers for each message
4-
which will be consumed by this worker;
3+
To use a worker, you should resolve its dependencies (e.g., through DI container) and define handlers for each message
4+
that will be consumed by this worker;
55

66
Handlers are callables indexed by payload names. When a message is consumed from the queue, a callable associated with
77
its payload name is called.
@@ -10,7 +10,7 @@ its payload name is called.
1010

1111
Handler can be any callable with a couple of additions:
1212

13-
- If handler is provided as an array of two strings, it will be treated as a DI container service id and its method.
13+
- If a handler is provided as an array of two strings, it will be treated as a DI container service id and its method.
1414
E.g. `[ClassName::class, 'handle']` will be resolved to:
1515
```php
1616
$container
@@ -69,7 +69,7 @@ stdout_logfile=/var/www/my_project/log/yii-queue-worker.log
6969
In this case Supervisor should start 4 `queue:listen` workers. The worker output will be written
7070
to the specified log file.
7171

72-
For more info about Supervisor's configuration and usage see its [documentation](http://supervisord.org).
72+
For more info about Supervisor's configuration and usage, see its [documentation](http://supervisord.org).
7373

7474
### Systemd
7575

@@ -96,7 +96,7 @@ Restart=on-failure
9696
WantedBy=multi-user.target
9797
```
9898

99-
You need to reload systemd in order to re-read its configuration:
99+
You need to reload systemd to re-read its configuration:
100100

101101
```shell
102102
systemctl daemon-reload
@@ -133,4 +133,4 @@ Config example:
133133
* * * * * /usr/bin/php /var/www/my_project/yii queue:run
134134
```
135135

136-
In this case cron will run the command every minute.
136+
In this case, cron will run the command every minute.

src/Adapter/SynchronousAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ final class SynchronousAdapter implements AdapterInterface
2020
private string $channel;
2121

2222
public function __construct(
23-
private WorkerInterface $worker,
24-
private QueueInterface $queue,
23+
private readonly WorkerInterface $worker,
24+
private readonly QueueInterface $queue,
2525
string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL,
2626
) {
2727
$this->channel = ChannelNormalizer::normalize($channel);

src/Cli/SignalLoop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class SignalLoop implements LoopInterface
2828

2929
/**
3030
* @param int $memorySoftLimit Soft RAM limit in bytes. The loop won't let you continue to execute the program if
31-
* soft limit is reached. Zero means no limit.
31+
* soft limit is reached. Zero means no limit.
3232
*/
3333
public function __construct(protected int $memorySoftLimit = 0)
3434
{
@@ -61,7 +61,7 @@ protected function dispatchSignals(): bool
6161
{
6262
pcntl_signal_dispatch();
6363

64-
// Wait for resume signal until loop is suspended
64+
// Wait for resume signal until the loop is suspended
6565
while ($this->pause && !$this->exit) {
6666
usleep(10000);
6767
pcntl_signal_dispatch();

src/Debug/QueueCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function getSummary(): array
8383
return [];
8484
}
8585

86-
$countPushes = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes));
86+
$countPushes = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes));
8787
$countStatuses = count($this->statuses);
88-
$countProcessingMessages = array_sum(array_map(fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages));
88+
$countProcessingMessages = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages));
8989

9090
return [
9191
'queue' => [

src/Debug/QueueDecorator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
final class QueueDecorator implements QueueInterface
1414
{
1515
public function __construct(
16-
private QueueInterface $queue,
17-
private QueueCollector $collector,
16+
private readonly QueueInterface $queue,
17+
private readonly QueueCollector $collector,
1818
) {
1919
}
2020

src/Debug/QueueWorkerInterfaceProxy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
final class QueueWorkerInterfaceProxy implements WorkerInterface
1212
{
1313
public function __construct(
14-
private WorkerInterface $worker,
15-
private QueueCollector $collector,
14+
private readonly WorkerInterface $worker,
15+
private readonly QueueCollector $collector,
1616
) {
1717
}
1818

0 commit comments

Comments
 (0)