php-resque/lib/Resque/Failure.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2010-04-18 13:58:43 +00:00
<?php
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@bigcommerce.com>
2010-04-18 13:58:43 +00:00
* @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.
*
2012-03-02 01:13:34 +00:00
* @param object $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 $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.
2010-04-18 13:58:43 +00:00
*/
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) {
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;
}
}