Skip to content

Commit f70e80c

Browse files
Remove behaviors (yiisoft#130)
* Remove behaviors completely * Apply fixes from StyleCI * AbstractMessage is removed Co-authored-by: StyleCI Bot <[email protected]>
1 parent 2cf0974 commit f70e80c

26 files changed

+22
-651
lines changed

docs/guide/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ An extension for running tasks asynchronously via queues.
66

77
* [Usage basics](usage.md)
88
* [Migrating from `yii2-queue`](migrating-from-yii2-queue.md)
9-
* [Message behaviors](behaviors.md)
109
* [Errors and retryable jobs](retryable.md)
1110
* [Workers](worker.md)
1211
* [Adapter list](adapter-list.md)

docs/guide/behaviors.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ and more structured than the old one allowing better maintenance.
1717
There was a concept in [yiisoft/yii2-queue] called `Job`: you had to push it to the queue, and it was executed after
1818
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 3 types of data:
20+
- A `Message` is a class implementing `MessageInterface`. It contains 2 types of data:
2121
- Name. Worker uses it to find the right handler for a message.
2222
- Data. Any serializable data which should be used by the message handler.
23-
- Behaviors. Message behaviors used by adapters. For example, priority setting, message delaying, etc. [See more](behaviors.md).
2423

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

docs/guide/usage.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ $queue->push($message);
4545
To push a job into the queue that should run after 5 minutes:
4646

4747
```php
48-
$message->attachBehavior(new DelayBehavior(5 * 60));
49-
$queue->push($message);
48+
// TODO
5049
```
5150

5251
**Important:** Not every adapter (such as synchronous adapter) supports delayed execution.

src/Adapter/AdapterInterface.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use InvalidArgumentException;
88
use Yiisoft\Yii\Queue\Enum\JobStatus;
9-
use Yiisoft\Yii\Queue\Exception\BehaviorNotSupportedException;
109
use Yiisoft\Yii\Queue\Message\MessageInterface;
1110

1211
interface AdapterInterface
@@ -31,8 +30,6 @@ public function status(string $id): JobStatus;
3130
* Pushing a message to the queue. Adapter sets message ID if available.
3231
*
3332
* @param MessageInterface $message
34-
*
35-
* @throws BehaviorNotSupportedException Adapter may throw exception when it does not support all the attached behaviors.
3633
*/
3734
public function push(MessageInterface $message): void;
3835

src/Adapter/BehaviorChecker.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Adapter/SynchronousAdapter.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,21 @@
66

77
use InvalidArgumentException;
88
use Yiisoft\Yii\Queue\Enum\JobStatus;
9-
use Yiisoft\Yii\Queue\Message\Behaviors\ExecutableBehaviorInterface;
109
use Yiisoft\Yii\Queue\Message\MessageInterface;
1110
use Yiisoft\Yii\Queue\QueueFactory;
1211
use Yiisoft\Yii\Queue\QueueInterface;
1312
use Yiisoft\Yii\Queue\Worker\WorkerInterface;
1413

1514
final class SynchronousAdapter implements AdapterInterface
1615
{
17-
private const BEHAVIORS_AVAILABLE = [];
18-
1916
private array $messages = [];
20-
private WorkerInterface $worker;
21-
private QueueInterface $queue;
2217
private int $current = 0;
23-
private ?BehaviorChecker $behaviorChecker;
24-
private string $channel;
2518

2619
public function __construct(
27-
WorkerInterface $worker,
28-
QueueInterface $queue,
29-
string $channel = QueueFactory::DEFAULT_CHANNEL_NAME,
30-
?BehaviorChecker $behaviorChecker = null
20+
private WorkerInterface $worker,
21+
private QueueInterface $queue,
22+
private string $channel = QueueFactory::DEFAULT_CHANNEL_NAME,
3123
) {
32-
$this->worker = $worker;
33-
$this->queue = $queue;
34-
$this->channel = $channel;
35-
$this->behaviorChecker = $behaviorChecker;
3624
}
3725

3826
public function __destruct()
@@ -72,17 +60,6 @@ public function status(string $id): JobStatus
7260

7361
public function push(MessageInterface $message): void
7462
{
75-
$behaviors = $message->getBehaviors();
76-
if ($this->behaviorChecker !== null) {
77-
$this->behaviorChecker->check(self::class, $behaviors, self::BEHAVIORS_AVAILABLE);
78-
}
79-
80-
foreach ($behaviors as $behavior) {
81-
if ($behavior instanceof ExecutableBehaviorInterface) {
82-
$behavior->execute();
83-
}
84-
}
85-
8663
$key = count($this->messages) + $this->current;
8764
$this->messages[] = $message;
8865

src/Exception/BehaviorNotSupportedException.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Message/AbstractMessage.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Message/Behaviors/BehaviorInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)