1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Failed Resque job. |
||
5 | * |
||
6 | * @package Resque/Failure |
||
7 | * @author Chris Boulton <[email protected]> |
||
8 | * @license http://www.opensource.org/licenses/mit-license.php |
||
9 | */ |
||
10 | class Resque_Failure |
||
11 | { |
||
12 | /** |
||
13 | * @var string Class name representing the backend to pass failed jobs off to. |
||
14 | */ |
||
15 | private static $backend; |
||
16 | |||
17 | /** |
||
18 | * Create a new failed job on the backend. |
||
19 | * |
||
20 | * @param object $payload The contents of the job that has just failed. |
||
21 | * @param \Exception $exception The exception generated when the job failed to run. |
||
22 | * @param \Resque_Worker $worker Instance of Resque_Worker that was running this job when it failed. |
||
23 | * @param string $queue The name of the queue that this job was fetched from. |
||
24 | */ |
||
25 | 2 | public static function create($payload, Exception $exception, Resque_Worker $worker, $queue) |
|
26 | { |
||
27 | 2 | $backend = self::getBackend(); |
|
28 | 2 | new $backend($payload, $exception, $worker, $queue); |
|
29 | 2 | } |
|
30 | |||
31 | /** |
||
32 | * Create a new failed job on the backend from PHP 7 errors. |
||
33 | * |
||
34 | * @param object $payload The contents of the job that has just failed. |
||
35 | * @param \Error $exception The PHP 7 error generated when the job failed to run. |
||
36 | * @param \Resque_Worker $worker Instance of Resque_Worker that was running this job when it failed. |
||
37 | * @param string $queue The name of the queue that this job was fetched from. |
||
38 | */ |
||
39 | public static function createFromError($payload, Error $exception, Resque_Worker $worker, $queue) |
||
40 | { |
||
41 | $backend = self::getBackend(); |
||
42 | new $backend($payload, $exception, $worker, $queue); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Return an instance of the backend for saving job failures. |
||
47 | * |
||
48 | * @return object Instance of backend object. |
||
49 | */ |
||
50 | 2 | public static function getBackend() |
|
51 | { |
||
52 | 2 | if (self::$backend === null) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
53 | 1 | self::$backend = 'Resque_Failure_Redis'; |
|
54 | } |
||
55 | |||
56 | 2 | return self::$backend; |
|
0 ignored issues
–
show
|
|||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Set the backend to use for raised job failures. The supplied backend |
||
61 | * should be the name of a class to be instantiated when a job fails. |
||
62 | * It is your responsibility to have the backend class loaded (or autoloaded) |
||
63 | * |
||
64 | * @param string $backend The class name of the backend to pipe failures to. |
||
65 | */ |
||
66 | public static function setBackend($backend) |
||
67 | { |
||
68 | self::$backend = $backend; |
||
69 | } |
||
70 | } |
||
71 |