Skip to content

Commit c35c228

Browse files
committed
Added fail state
1 parent 92533b6 commit c35c228

File tree

2 files changed

+32
-82
lines changed

2 files changed

+32
-82
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Serghei Iakovlev <[email protected]>
2+
Stuart Carnie <[email protected]>

src/Job/QlessJob.php

Lines changed: 30 additions & 82 deletions
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
*

0 commit comments

Comments
 (0)