Test Setup Failed
Pull Request — master (#7)
by Matthew
14:04
created

JobManager::saveHistory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Dtc\QueueBundle\RabbitMQ;
4
5
use Dtc\QueueBundle\Model\Job;
6
use Dtc\QueueBundle\Model\JobManagerInterface;
7
use PhpAmqpLib\Channel\AMQPChannel;
8
use PhpAmqpLib\Connection\AbstractConnection;
9
use PhpAmqpLib\Message\AMQPMessage;
10
11
class JobManager implements JobManagerInterface
12
{
13
    /** @var AMQPChannel */
14
    protected $channel;
15
16
    /** @var AbstractConnection */
17
    protected $connection;
18
    protected $queueArgs;
19
    protected $exchangeArgs;
20
21
    protected $channelSetup = false;
22
23
    public function setExchangeArgs($exchange, $type, $passive, $durable, $autoDelete)
0 ignored issues
show
Unused Code introduced by
The parameter $exchange is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $passive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $durable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $autoDelete is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $this->exchangeArgs = func_get_args();
26
    }
27
28
    public function setQueueArgs($queue, $passive, $durable, $exclusive, $autoDelete)
0 ignored issues
show
Unused Code introduced by
The parameter $queue is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $passive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $durable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $exclusive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $autoDelete is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $this->queueArgs = func_get_args();
31
    }
32
33
    public function setAMQPConnection(AbstractConnection $connection)
34
    {
35
        $this->connection = $connection;
36
        $this->channel = $connection->channel();
37
    }
38
39
    protected function setupChannel()
40
    {
41
        if (!$this->channelSetup) {
42
            call_user_func_array([$this->channel, 'exchange_declare'], $this->exchangeArgs);
43
            call_user_func_array([$this->channel, 'queue_declare'], $this->queueArgs);
44
            $this->channel->queue_bind($this->queueArgs[0], $this->exchangeArgs[0]);
45
            $this->channelSetup = true;
46
        }
47
    }
48
49
    public function save(\Dtc\QueueBundle\Model\Job $job)
50
    {
51
        $this->setupChannel();
52
        $msg = new AMQPMessage($job->toMessage());
53
        $this->channel->basic_publish($msg, $this->exchangeArgs[0]);
54
55
        return $job;
56
    }
57
58
    public function getJob($workerName = null, $methodName = null, $prioritize = true)
59
    {
60
        if ($methodName) {
61
            throw new \Exception('Unsupported');
62
        }
63
64
        $this->setupChannel();
65
        $message = $this->channel->basic_get($this->queueArgs[0]);
66
        if ($message) {
67
            $job = new Job();
68
            $job->fromMessage($message->body);
69
            $job->setId($message->delivery_info['delivery_tag']);
70
71
            return $job;
72
        }
73
74
        return null;
75
    }
76
77
    public function deleteJob(\Dtc\QueueBundle\Model\Job $job)
78
    {
79
        throw new \Exception('unsupported');
80
    }
81
82
    // Save History get called upon completion of the job
83
    public function saveHistory(\Dtc\QueueBundle\Model\Job $job)
84
    {
85
        $deliveryTag = $job->getId();
86
        $this->channel->basic_ack($deliveryTag);
87
88
        return;
89
    }
90
91
    public function __destruct()
92
    {
93
        $this->channel->close();
94
    }
95
96 View Code Duplication
    public function getJobCount($workerName = null, $methodName = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        if ($methodName) {
99
            throw new \Exception('Unsupported');
100
        }
101
102
        if ($workerName) {
103
            throw new \Exception('Unsupported');
104
        }
105
    }
106
107
    public function resetErroneousJobs($workerName = null, $methodName = null)
108
    {
109
        throw new \Exception('Unsupported');
110
    }
111
112
    public function pruneErroneousJobs($workerName = null, $methodName = null)
113
    {
114
        throw new \Exception('Unsupported');
115
    }
116
117
    public function getStatus()
118
    {
119
        throw new \Exception('Unsupported');
120
    }
121
}
122