~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/lib/Resque/Failure.php

  • Committer: Keith Hughitt
  • Date: 2012-04-23 16:02:25 UTC
  • mto: This revision was merged to the branch mainline in revision 732.
  • Revision ID: keith.hughitt@nasa.gov-20120423160225-xzoh82ejf37c8yr7
Incorporated HVPull code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
require_once dirname(__FILE__) . '/Failure/Interface.php';
 
3
 
 
4
/**
 
5
 * Failed Resque job.
 
6
 *
 
7
 * @package             Resque/Failure
 
8
 * @author              Chris Boulton <chris.boulton@interspire.com>
 
9
 * @copyright   (c) 2010 Chris Boulton
 
10
 * @license             http://www.opensource.org/licenses/mit-license.php
 
11
 */
 
12
class Resque_Failure
 
13
{
 
14
        /**
 
15
         * @var string Class name representing the backend to pass failed jobs off to.
 
16
         */
 
17
        private static $backend;
 
18
 
 
19
        /**
 
20
         * Create a new failed job on the backend.
 
21
         *
 
22
         * @param object $payload The contents of the job that has just failed.
 
23
         * @param object $exception The exception generated when the job failed to run.
 
24
         * @param object $worker Instance of Resque_Worker that was running this job when it failed.
 
25
         * @param string $queue The name of the queue that this job was fetched from.
 
26
         */
 
27
        public static function create($payload, Exception $exception, Resque_Worker $worker, $queue)
 
28
        {
 
29
                $backend = self::getBackend();
 
30
                new $backend($payload, $exception, $worker, $queue);
 
31
        }
 
32
 
 
33
        /**
 
34
         * Return an instance of the backend for saving job failures.
 
35
         *
 
36
         * @return object Instance of backend object.
 
37
         */
 
38
        public static function getBackend()
 
39
        {
 
40
                if(self::$backend === null) {
 
41
                        require  dirname(__FILE__) . '/Failure/Redis.php';
 
42
                        self::$backend = 'Resque_Failure_Redis';
 
43
                }
 
44
 
 
45
                return self::$backend;
 
46
        }
 
47
 
 
48
        /**
 
49
         * Set the backend to use for raised job failures. The supplied backend
 
50
         * should be the name of a class to be instantiated when a job fails.
 
51
         * It is your responsibility to have the backend class loaded (or autoloaded)
 
52
         *
 
53
         * @param string $backend The class name of the backend to pipe failures to.
 
54
         */
 
55
        public static function setBackend($backend)
 
56
        {
 
57
                self::$backend = $backend;
 
58
        }
 
59
}
 
 
b'\\ No newline at end of file'