Skip to content

Commit c2198da

Browse files
committed
[job-queue] sync with latest design changes.
1 parent 0748873 commit c2198da

8 files changed

+20
-27
lines changed

pkg/job-queue/CalculateRootJobStatusProcessor.php

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Enqueue\JobQueue;
44

5+
use Enqueue\Client\CommandSubscriberInterface;
56
use Enqueue\Client\ProducerInterface;
6-
use Enqueue\Client\TopicSubscriberInterface;
77
use Enqueue\Consumption\Result;
88
use Enqueue\JobQueue\Doctrine\JobStorage;
99
use Enqueue\Util\JSON;
@@ -12,7 +12,7 @@
1212
use Interop\Queue\PsrProcessor;
1313
use Psr\Log\LoggerInterface;
1414

15-
class CalculateRootJobStatusProcessor implements PsrProcessor, TopicSubscriberInterface
15+
class CalculateRootJobStatusProcessor implements PsrProcessor, CommandSubscriberInterface
1616
{
1717
/**
1818
* @var JobStorage
@@ -34,12 +34,6 @@ class CalculateRootJobStatusProcessor implements PsrProcessor, TopicSubscriberIn
3434
*/
3535
private $logger;
3636

37-
/**
38-
* @param JobStorage $jobStorage
39-
* @param CalculateRootJobStatusService $calculateRootJobStatusCase
40-
* @param ProducerInterface $producer
41-
* @param LoggerInterface $logger
42-
*/
4337
public function __construct(
4438
JobStorage $jobStorage,
4539
CalculateRootJobStatusService $calculateRootJobStatusCase,
@@ -52,9 +46,6 @@ public function __construct(
5246
$this->logger = $logger;
5347
}
5448

55-
/**
56-
* {@inheritdoc}
57-
*/
5849
public function process(PsrMessage $message, PsrContext $context)
5950
{
6051
$data = JSON::decode($message->getBody());
@@ -83,11 +74,8 @@ public function process(PsrMessage $message, PsrContext $context)
8374
return Result::ACK;
8475
}
8576

86-
/**
87-
* {@inheritdoc}
88-
*/
89-
public static function getSubscribedTopics()
77+
public static function getSubscribedCommand()
9078
{
91-
return [Topics::CALCULATE_ROOT_JOB_STATUS];
79+
return Commands::CALCULATE_ROOT_JOB_STATUS;
9280
}
9381
}

pkg/job-queue/Commands.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Enqueue\JobQueue;
4+
5+
class Commands
6+
{
7+
const CALCULATE_ROOT_JOB_STATUS = 'enqueue.message_queue.job.calculate_root_job_status';
8+
}

pkg/job-queue/DependentJobProcessor.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@ public function process(PsrMessage $message, PsrContext $context)
111111
return Result::ACK;
112112
}
113113

114-
/**
115-
* {@inheritdoc}
116-
*/
117114
public static function getSubscribedTopics()
118115
{
119-
return [Topics::ROOT_JOB_STOPPED];
116+
return Topics::ROOT_JOB_STOPPED;
120117
}
121118
}

pkg/job-queue/JobProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected function saveJob(Job $job)
260260
*/
261261
protected function sendCalculateRootJobStatusEvent(Job $job)
262262
{
263-
$this->producer->sendEvent(Topics::CALCULATE_ROOT_JOB_STATUS, [
263+
$this->producer->sendEvent(Commands::CALCULATE_ROOT_JOB_STATUS, [
264264
'jobId' => $job->getId(),
265265
]);
266266
}

pkg/job-queue/Tests/CalculateRootJobStatusProcessorTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Enqueue\Consumption\Result;
77
use Enqueue\JobQueue\CalculateRootJobStatusProcessor;
88
use Enqueue\JobQueue\CalculateRootJobStatusService;
9+
use Enqueue\JobQueue\Commands;
910
use Enqueue\JobQueue\Doctrine\JobStorage;
1011
use Enqueue\JobQueue\Job;
1112
use Enqueue\JobQueue\Topics;
@@ -28,8 +29,8 @@ public function testCouldBeConstructedWithRequiredArguments()
2829
public function testShouldReturnSubscribedTopicNames()
2930
{
3031
$this->assertEquals(
31-
[Topics::CALCULATE_ROOT_JOB_STATUS],
32-
CalculateRootJobStatusProcessor::getSubscribedTopics()
32+
Commands::CALCULATE_ROOT_JOB_STATUS,
33+
CalculateRootJobStatusProcessor::getSubscribedCommand()
3334
);
3435
}
3536

pkg/job-queue/Tests/DependentJobProcessorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DependentJobProcessorTest extends \PHPUnit\Framework\TestCase
1818
public function testShouldReturnSubscribedTopicNames()
1919
{
2020
$this->assertEquals(
21-
[Topics::ROOT_JOB_STOPPED],
21+
Topics::ROOT_JOB_STOPPED,
2222
DependentJobProcessor::getSubscribedTopics()
2323
);
2424
}

pkg/job-queue/Tests/JobProcessorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace Enqueue\JobQueue\Tests;
44

55
use Enqueue\Client\ProducerInterface;
6+
use Enqueue\JobQueue\Commands;
67
use Enqueue\JobQueue\Doctrine\JobStorage;
78
use Enqueue\JobQueue\DuplicateJobException;
89
use Enqueue\JobQueue\Job;
910
use Enqueue\JobQueue\JobProcessor;
10-
use Enqueue\JobQueue\Topics;
1111
use PHPUnit\Framework\TestCase;
1212

1313
class JobProcessorTest extends TestCase
@@ -170,7 +170,7 @@ public function testCreateChildJobShouldCreateAndSaveJobAndPublishRecalculateRoo
170170
$producer
171171
->expects($this->once())
172172
->method('sendEvent')
173-
->with(Topics::CALCULATE_ROOT_JOB_STATUS, ['jobId' => 12345])
173+
->with(Commands::CALCULATE_ROOT_JOB_STATUS, ['jobId' => 12345])
174174
;
175175

176176
$processor = new JobProcessor($storage, $producer);

pkg/job-queue/Topics.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44

55
class Topics
66
{
7-
const CALCULATE_ROOT_JOB_STATUS = 'enqueue.message_queue.job.calculate_root_job_status';
87
const ROOT_JOB_STOPPED = 'enqueue.message_queue.job.root_job_stopped';
98
}

0 commit comments

Comments
 (0)