Skip to content

Commit da7443b

Browse files
authored
Merge pull request vyuldashev#131 from vladimir-yuldashev/analysis-z3pPgG
Apply fixes from StyleCI
2 parents 167a4b1 + a85b1a3 commit da7443b

File tree

6 files changed

+350
-358
lines changed

6 files changed

+350
-358
lines changed

src/VladimirYuldashev/LaravelQueueRabbitMQ/LaravelQueueRabbitMQServiceProvider.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@
99
class LaravelQueueRabbitMQServiceProvider extends ServiceProvider
1010
{
1111

12-
/**
13-
* Register the service provider.
14-
*
15-
* @return void
16-
*/
17-
public function register()
18-
{
19-
$this->app->booted(function () {
20-
21-
Queue::extend('rabbitmq', function () {
22-
return new RabbitMQConnector;
23-
});
24-
25-
});
26-
}
27-
}
12+
/**
13+
* Register the service provider.
14+
*
15+
* @return void
16+
*/
17+
public function register()
18+
{
19+
$this->app->booted(function () {
20+
Queue::extend('rabbitmq', function () {
21+
return new RabbitMQConnector;
22+
});
23+
});
24+
}
25+
}

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/Connectors/RabbitMQConnector.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
class RabbitMQConnector implements ConnectorInterface
1010
{
1111

12-
/**
13-
* Establish a queue connection.
14-
*
15-
* @param array $config
16-
*
17-
* @return \Illuminate\Queue\QueueInterface
18-
*/
19-
public function connect(array $config)
20-
{
21-
// create connection with AMQP
22-
$connection = new AMQPConnection($config['host'], $config['port'], $config['login'], $config['password'], $config['vhost']);
12+
/**
13+
* Establish a queue connection.
14+
*
15+
* @param array $config
16+
*
17+
* @return \Illuminate\Queue\QueueInterface
18+
*/
19+
public function connect(array $config)
20+
{
21+
// create connection with AMQP
22+
$connection = new AMQPConnection($config['host'], $config['port'], $config['login'], $config['password'], $config['vhost']);
2323

24-
return new RabbitMQQueue(
25-
$connection,
26-
$config
27-
);
28-
}
29-
}
24+
return new RabbitMQQueue(
25+
$connection,
26+
$config
27+
);
28+
}
29+
}

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php

Lines changed: 100 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,106 +10,104 @@
1010

1111
class RabbitMQJob extends Job
1212
{
13-
14-
protected $channel;
15-
protected $queue;
16-
protected $connection;
17-
protected $message;
18-
19-
public function __construct($container, RabbitMQQueue $connection, AMQPChannel $channel, $queue, AMQPMessage $message)
20-
{
21-
$this->container = $container;
22-
$this->connection = $connection;
23-
$this->channel = $channel;
24-
$this->queue = $queue;
25-
$this->message = $message;
26-
}
27-
28-
/**
29-
* Fire the job.
30-
*
31-
* @return void
32-
*/
33-
public function fire()
34-
{
35-
$this->resolveAndFire(json_decode($this->message->body, true));
36-
}
37-
38-
/**
39-
* Get the raw body string for the job.
40-
*
41-
* @return string
42-
*/
43-
public function getRawBody()
44-
{
45-
return $this->message->body;
46-
}
47-
48-
/**
49-
* Delete the job from the queue.
50-
*
51-
* @return void
52-
*/
53-
public function delete()
54-
{
55-
parent::delete();
56-
57-
$this->channel->basic_ack($this->message->delivery_info['delivery_tag']);
58-
}
59-
60-
/**
61-
* Get queue name
62-
*
63-
* @return string
64-
*/
65-
public function getQueue()
66-
{
67-
return $this->queue;
68-
}
69-
70-
/**
71-
* Release the job back into the queue.
72-
*
73-
* @param int $delay
74-
*
75-
* @return void
76-
*/
77-
public function release($delay = 0)
78-
{
79-
$this->delete();
80-
81-
$body = $this->message->body;
82-
$body = json_decode($body, true);
83-
84-
$attempts = $this->attempts();
85-
86-
// write attempts to body
87-
$body['attempts'] = $attempts + 1;
88-
89-
$this->connection->pushRaw(json_encode($body), $this->getQueue(),
90-
$delay > 0 ? [ 'delay' => $delay ] : []);
91-
}
92-
93-
/**
94-
* Get the number of times the job has been attempted.
95-
*
96-
* @return int
97-
*/
98-
public function attempts()
99-
{
100-
$body = json_decode($this->message->body, true);
101-
102-
return isset($body['attempts']) ? $body['attempts'] : 0;
103-
}
104-
105-
/**
106-
* Get the job identifier.
107-
*
108-
* @return string
109-
*/
110-
public function getJobId()
111-
{
112-
return $this->message->body;
113-
}
114-
13+
protected $channel;
14+
protected $queue;
15+
protected $connection;
16+
protected $message;
17+
18+
public function __construct($container, RabbitMQQueue $connection, AMQPChannel $channel, $queue, AMQPMessage $message)
19+
{
20+
$this->container = $container;
21+
$this->connection = $connection;
22+
$this->channel = $channel;
23+
$this->queue = $queue;
24+
$this->message = $message;
25+
}
26+
27+
/**
28+
* Fire the job.
29+
*
30+
* @return void
31+
*/
32+
public function fire()
33+
{
34+
$this->resolveAndFire(json_decode($this->message->body, true));
35+
}
36+
37+
/**
38+
* Get the raw body string for the job.
39+
*
40+
* @return string
41+
*/
42+
public function getRawBody()
43+
{
44+
return $this->message->body;
45+
}
46+
47+
/**
48+
* Delete the job from the queue.
49+
*
50+
* @return void
51+
*/
52+
public function delete()
53+
{
54+
parent::delete();
55+
56+
$this->channel->basic_ack($this->message->delivery_info['delivery_tag']);
57+
}
58+
59+
/**
60+
* Get queue name
61+
*
62+
* @return string
63+
*/
64+
public function getQueue()
65+
{
66+
return $this->queue;
67+
}
68+
69+
/**
70+
* Release the job back into the queue.
71+
*
72+
* @param int $delay
73+
*
74+
* @return void
75+
*/
76+
public function release($delay = 0)
77+
{
78+
$this->delete();
79+
80+
$body = $this->message->body;
81+
$body = json_decode($body, true);
82+
83+
$attempts = $this->attempts();
84+
85+
// write attempts to body
86+
$body['attempts'] = $attempts + 1;
87+
88+
$this->connection->pushRaw(json_encode($body), $this->getQueue(),
89+
$delay > 0 ? [ 'delay' => $delay ] : []);
90+
}
91+
92+
/**
93+
* Get the number of times the job has been attempted.
94+
*
95+
* @return int
96+
*/
97+
public function attempts()
98+
{
99+
$body = json_decode($this->message->body, true);
100+
101+
return isset($body['attempts']) ? $body['attempts'] : 0;
102+
}
103+
104+
/**
105+
* Get the job identifier.
106+
*
107+
* @return string
108+
*/
109+
public function getJobId()
110+
{
111+
return $this->message->body;
112+
}
115113
}

0 commit comments

Comments
 (0)