Skip to content

Commit c31f8b4

Browse files
committed
[consumption] Remove onInterrupted. Add onEnd. Remove context object and consumption interrupted exception.
1 parent 6783f04 commit c31f8b4

17 files changed

+215
-826
lines changed

pkg/enqueue/Client/ConsumptionExtension/FlushSpoolProducerExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Enqueue\Client\ConsumptionExtension;
44

55
use Enqueue\Client\SpoolProducer;
6-
use Enqueue\Consumption\Context;
6+
use Enqueue\Consumption\Context\End;
77
use Enqueue\Consumption\Context\PostMessageReceived;
88
use Enqueue\Consumption\EmptyExtensionTrait;
99
use Enqueue\Consumption\ExtensionInterface;
@@ -30,7 +30,7 @@ public function onPostMessageReceived(PostMessageReceived $context): void
3030
$this->producer->flush();
3131
}
3232

33-
public function onInterrupted(Context $context)
33+
public function onEnd(End $context): void
3434
{
3535
$this->producer->flush();
3636
}

pkg/enqueue/Consumption/ChainExtension.php

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

33
namespace Enqueue\Consumption;
44

5+
use Enqueue\Consumption\Context\End;
56
use Enqueue\Consumption\Context\MessageReceived;
67
use Enqueue\Consumption\Context\MessageResult;
78
use Enqueue\Consumption\Context\PostConsume;
@@ -87,10 +88,10 @@ public function onPostConsume(PostConsume $context): void
8788
}
8889
}
8990

90-
public function onInterrupted(Context $context)
91+
public function onEnd(End $context): void
9192
{
9293
foreach ($this->extensions as $extension) {
93-
$extension->onInterrupted($context);
94+
$extension->onEnd($context);
9495
}
9596
}
9697
}

pkg/enqueue/Consumption/Context.php

Lines changed: 0 additions & 233 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Enqueue\Consumption\Context;
4+
5+
use Interop\Queue\Context;
6+
use Psr\Log\LoggerInterface;
7+
8+
final class End
9+
{
10+
/**
11+
* @var Context
12+
*/
13+
private $context;
14+
15+
/**
16+
* @var int
17+
*/
18+
private $startTime;
19+
20+
/**
21+
* @var int
22+
*/
23+
private $endTime;
24+
25+
/**
26+
* @var LoggerInterface
27+
*/
28+
private $logger;
29+
30+
public function __construct(Context $context, int $startTime, int $endTime, LoggerInterface $logger)
31+
{
32+
$this->context = $context;
33+
$this->logger = $logger;
34+
$this->startTime = $startTime;
35+
$this->endTime = $endTime;
36+
}
37+
38+
public function getContext(): Context
39+
{
40+
return $this->context;
41+
}
42+
43+
public function getLogger(): LoggerInterface
44+
{
45+
return $this->logger;
46+
}
47+
48+
/**
49+
* In milliseconds.
50+
*/
51+
public function getStartTime(): int
52+
{
53+
return $this->startTime;
54+
}
55+
56+
/**
57+
* In milliseconds.
58+
*/
59+
public function getEndTime(): int
60+
{
61+
return $this->startTime;
62+
}
63+
}

pkg/enqueue/Consumption/EmptyExtensionTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Enqueue\Consumption;
44

5+
use Enqueue\Consumption\Context\End;
56
use Enqueue\Consumption\Context\MessageReceived;
67
use Enqueue\Consumption\Context\MessageResult;
78
use Enqueue\Consumption\Context\PostConsume;
@@ -45,7 +46,7 @@ public function onPostConsume(PostConsume $context): void
4546
{
4647
}
4748

48-
public function onInterrupted(Context $context)
49+
public function onEnd(End $context): void
4950
{
5051
}
5152
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Enqueue\Consumption;
4+
5+
use Enqueue\Consumption\Context\End;
6+
7+
interface EndExtensionInterface
8+
{
9+
/**
10+
* Executed only once just before QueueConsumer::consume returns.
11+
*/
12+
public function onEnd(End $context): void;
13+
}

pkg/enqueue/Consumption/Exception/ConsumptionInterruptedException.php

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

pkg/enqueue/Consumption/ExtensionInterface.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
namespace Enqueue\Consumption;
44

5-
interface ExtensionInterface extends StartExtensionInterface, PreSubscribeExtensionInterface, PreConsumeExtensionInterface, MessageReceivedExtensionInterface, PostMessageReceivedExtensionInterface, MessageResultExtensionInterface, ProcessorExceptionExtensionInterface, PostConsumeExtensionInterface
5+
interface ExtensionInterface extends StartExtensionInterface, PreSubscribeExtensionInterface, PreConsumeExtensionInterface, MessageReceivedExtensionInterface, PostMessageReceivedExtensionInterface, MessageResultExtensionInterface, ProcessorExceptionExtensionInterface, PostConsumeExtensionInterface, EndExtensionInterface
66
{
7-
/**
8-
* Called when the consumption was interrupted by an extension or exception
9-
* In case of exception it will be present in the context.
10-
*
11-
* @param Context $context
12-
*/
13-
public function onInterrupted(Context $context);
147
}

0 commit comments

Comments
 (0)