2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
2010-04-20 00:59:06 +00:00
|
|
|
require_once dirname(__FILE__) . '/Failure/Interface.php';
|
2010-04-18 13:58:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Failed Resque job.
|
|
|
|
*
|
|
|
|
* @package Resque/Failure
|
|
|
|
* @author Chris Boulton <chris.boulton@interspire.com>
|
|
|
|
* @copyright (c) 2010 Chris Boulton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*/
|
|
|
|
class Resque_Failure
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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 $payload The contents of the job that has just failed.
|
|
|
|
* @param object $exception The exception generated when the job failed to run.
|
|
|
|
* @param object $worker Instance of Resque_Worker 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, Resque_Worker $worker, $queue)
|
|
|
|
{
|
|
|
|
$backend = self::getBackend();
|
|
|
|
new $backend($payload, $exception, $worker, $queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the backend for saving job failures.
|
|
|
|
*
|
|
|
|
* @return object Instance of backend object.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function getBackend()
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
if(self::$backend === null) {
|
2010-04-20 00:59:06 +00:00
|
|
|
require dirname(__FILE__) . '/Failure/Redis.php';
|
2010-04-18 13:58:43 +00:00
|
|
|
self::$backend = 'Resque_Failure_Redis';
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function setBackend($backend)
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
self::$backend = $backend;
|
|
|
|
}
|
|
|
|
}
|