-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathFailureHandler.php
More file actions
78 lines (70 loc) · 2.41 KB
/
FailureHandler.php
File metadata and controls
78 lines (70 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Resque;
use Resque\Worker\ResqueWorker;
use Exception;
use Error;
/**
* Failed Resque job.
*
* @package Resque/FailureHandler
* @author Chris Boulton <chris@bigcommerce.com>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class FailureHandler
{
/**
* @var string Class name representing the backend to pass failed jobs off to.
*/
private static $backend;
/**
* Create a new failed job on the backend.
*
* @param object|array $payload The contents of the job that has just failed.
* @param \Exception $exception The exception generated when the job failed to run.
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
* that was running this job when it failed.
* @param string $queue The name of the queue that this job was fetched from.
*/
public static function create($payload, Exception $exception, ResqueWorker $worker, $queue)
{
$backend = self::getBackend();
new $backend($payload, $exception, $worker, $queue);
}
/**
* Create a new failed job on the backend from PHP 7 errors.
*
* @param object|array $payload The contents of the job that has just failed.
* @param \Error $exception The PHP 7 error generated when the job failed to run.
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
* that was running this job when it failed.
* @param string $queue The name of the queue that this job was fetched from.
*/
public static function createFromError($payload, Error $exception, ResqueWorker $worker, $queue)
{
$backend = self::getBackend();
new $backend($payload, $exception, $worker, $queue);
}
/**
* Return an instance of the backend for saving job failures.
*
* @return object|string Instance of backend object.
*/
public static function getBackend()
{
if (self::$backend === null) {
self::$backend = 'Resque\Failure\RedisFailure';
}
return self::$backend;
}
/**
* Set the backend to use for raised job failures. The supplied backend
* should be the name of a class to be instantiated when a job fails.
* It is your responsibility to have the backend class loaded (or autoloaded)
*
* @param string $backend The class name of the backend to pipe failures to.
*/
public static function setBackend($backend)
{
self::$backend = $backend;
}
}