Skip to content

Commit 4019b44

Browse files
authored
Merge pull request #4 from pdffiller/release/1.2
Release/1.2
2 parents 92533b6 + 46953c9 commit 4019b44

15 files changed

+296
-168
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Serhii Osadchyi <[email protected]>

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018 PDFfiller
3+
Copyright (c) 2018-2019 PDFfiller
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Also you can set Qless queue as default in `config/queue.php`
3131
'default' => env('QUEUE_DRIVER', 'qless'),
3232
```
3333

34-
And redis connection in `config/database.php`
34+
Redis connection in `config/database.php`
3535

3636
```php
3737
'redis' => [
@@ -49,6 +49,23 @@ And redis connection in `config/database.php`
4949
],
5050
```
5151

52+
And add Laravel Qless service provider to app.php
53+
54+
```php
55+
<?php
56+
57+
return [
58+
//...
59+
'providers' => [
60+
//...
61+
/**
62+
* Qless
63+
*/
64+
LaravelQless\LaravelQlessServiceProvider::class,
65+
]
66+
];
67+
```
68+
5269
## Usage
5370

5471
Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues
@@ -80,7 +97,7 @@ Than you can put job to all subscribers.
8097
/**
8198
* Put job to few queues
8299
*/
83-
\Queue::pushToSubscriber('this.is.test', TestQless::class, ['test' => 'test']);
100+
\Queue::pushToTopic('this.is.test', TestQless::class, ['test' => 'test']);
84101
// Push job to queue1 and queue2, but not to queue3
85102

86103
```

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"ext-json": "*",
19-
"pdffiller/qless-php": "3.3.0"
19+
"pdffiller/qless-php": "3.4.0"
2020
},
2121
"require-dev": {
2222
"illuminate/events": "5.6.*|5.7.*",

config/queue.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

33
return [
4+
'default' => 'qless',
5+
46
'connections' => [
57
'qless' => [
68
'driver' => 'qless',
7-
'connection' => 'default',
9+
'connection' => 'qless',
810
'queue' => 'default',
911
'redis_connection' => 'qless',
1012
],

examples/Job/ExampleJob.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace LaravelQless\Examples\Job;
44

5-
use LaravelQless\Contracts\QlessJob;
5+
use LaravelQless\Job\AbstractJob;
66
use Qless\Jobs\BaseJob;
77

8-
class ExampleJob implements QlessJob
8+
class ExampleJob extends AbstractJob
99
{
10-
1110
/**
1211
* Execute the job.
1312
*

src/Job/AbstractJob.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace LaravelQless\Job;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Contracts\Support\Arrayable;
8+
use Illuminate\Foundation\Bus\Dispatchable;
9+
use Qless\Jobs\BaseJob;
10+
use LaravelQless\Contracts\QlessJob;
11+
12+
/**
13+
* Class AbstractJob
14+
* @package LaravelQless\Job
15+
*/
16+
abstract class AbstractJob implements QlessJob, ShouldQueue, Arrayable
17+
{
18+
use Dispatchable, Queueable;
19+
/**
20+
* @var array
21+
*/
22+
protected $data = [];
23+
24+
public function __construct(array $data = [])
25+
{
26+
$this->data = $data;
27+
}
28+
29+
/**
30+
* @param BaseJob $job
31+
* @return mixed
32+
*/
33+
abstract public function perform(BaseJob $job);
34+
35+
/**
36+
* @return array
37+
*/
38+
public function toArray(): array
39+
{
40+
return (array) $this->data;
41+
}
42+
}

src/Job/QlessJob.php

+30-82
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace LaravelQless\Job;
44

55
use Carbon\Carbon;
6+
use Illuminate\Container\Container;
67
use Illuminate\Queue\Jobs\Job;
78
use Illuminate\Contracts\Queue\Job as JobContract;
9+
use Illuminate\Queue\ManuallyFailedException;
10+
use LaravelQless\Queue\QlessQueue;
811
use Qless\Jobs\BaseJob;
912
use LaravelQless\Contracts\JobHandler;
1013

@@ -20,36 +23,41 @@ class QlessJob extends Job implements JobContract
2023
protected $job;
2124

2225
/**
23-
* @var string
26+
* @var QlessQueue
2427
*/
25-
protected $payload;
28+
protected $qlessQueue;
2629

2730
/**
2831
* @var string
2932
*/
30-
protected $connectionName;
31-
32-
/**
33-
* @var bool
34-
*/
35-
protected $deleted = false;
36-
37-
/**
38-
* @var bool
39-
*/
40-
protected $released = false;
33+
protected $payload;
4134

4235
/**
4336
* @var JobHandler
4437
*/
4538
protected $handler;
4639

47-
public function __construct(BaseJob $job, string $payload, string $connectionName)
48-
{
40+
/**
41+
* QlessJob constructor.
42+
* @param Container $container
43+
* @param QlessQueue $qlessQueue
44+
* @param JobHandler $handler
45+
* @param BaseJob $job
46+
* @param string $payload
47+
*/
48+
public function __construct(
49+
Container $container,
50+
QlessQueue $qlessQueue,
51+
JobHandler $handler,
52+
BaseJob $job,
53+
string $payload
54+
) {
55+
$this->container = $container;
56+
$this->qlessQueue = $qlessQueue;
4957
$this->job = $job;
5058
$this->payload = $payload;
51-
$this->connectionName = $connectionName;
52-
$this->handler = app()->make(JobHandler::class);
59+
$this->connectionName = $qlessQueue->getConnectionName();
60+
$this->handler = $handler;
5361
}
5462

5563
/**
@@ -88,6 +96,10 @@ public function payload()
8896
public function fire()
8997
{
9098
$this->handler->perform($this->job);
99+
100+
if ($this->job->failed) {
101+
$this->failed(new ManuallyFailedException());
102+
}
91103
}
92104

93105
/**
@@ -99,8 +111,7 @@ public function fire()
99111
public function release($delay = 0)
100112
{
101113
$this->released = true;
102-
return \Queue::connection($this->getConnectionName())
103-
->later($delay, $this->job->getKlass(), $this->job->getData(), $this->job->getQueue());
114+
return $this->qlessQueue->later($delay, $this->job->getKlass(), $this->job->getData(), $this->job->getQueue());
104115
}
105116

106117
/**
@@ -114,36 +125,6 @@ public function delete()
114125
$this->deleted = true;
115126
}
116127

117-
/**
118-
* Determine if the job has been deleted.
119-
*
120-
* @return bool
121-
*/
122-
public function isDeleted()
123-
{
124-
return $this->deleted;
125-
}
126-
127-
/**
128-
* Determine if the job has been deleted.
129-
*
130-
* @return bool
131-
*/
132-
public function isReleased()
133-
{
134-
return $this->released;
135-
}
136-
137-
/**
138-
* Determine if the job has been deleted or released.
139-
*
140-
* @return bool
141-
*/
142-
public function isDeletedOrReleased()
143-
{
144-
return $this->isDeleted() || $this->isReleased();
145-
}
146-
147128
/**
148129
* Get the number of times the job has been attempted.
149130
*
@@ -154,17 +135,6 @@ public function attempts()
154135
return $this->job->getRemaining();
155136
}
156137

157-
/**
158-
* Process an exception that caused the job to fail.
159-
*
160-
* @param \Throwable $e
161-
* @return void
162-
*/
163-
public function failed($e)
164-
{
165-
$this->job->fail($e->getCode(), $e->getMessage());
166-
}
167-
168138
/**
169139
* Get the number of times to attempt a job.
170140
*
@@ -205,28 +175,6 @@ public function getName()
205175
return $this->job->getKlass();
206176
}
207177

208-
/**
209-
* Get the resolved name of the queued job class.
210-
*
211-
* Resolves the name of "wrapped" jobs such as class-based handlers.
212-
*
213-
* @return string
214-
*/
215-
public function resolveName()
216-
{
217-
return $this->job->getKlass(); // ??
218-
}
219-
220-
/**
221-
* Get the name of the connection the job belongs to.
222-
*
223-
* @return string
224-
*/
225-
public function getConnectionName()
226-
{
227-
return $this->connectionName;
228-
}
229-
230178
/**
231179
* Get the name of the queue the job belongs to.
232180
*

src/Queue/QlessConnector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class QlessConnector implements ConnectorInterface
2121
*/
2222
public function connect(array $config): QlessQueue
2323
{
24-
$redisConnection = array_get($config, 'redis_connection', 'default');
24+
$redisConnection = array_get($config, 'redis_connection', 'qless');
2525

2626
$redisConfig = Config::get('database.redis.' . $redisConnection, []);
2727

0 commit comments

Comments
 (0)