-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from talis/move-to-package
Move into own package
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# resque-multiple-failure-queues | ||
Add-on for php-resque to allow multiple failure queues | ||
|
||
To use: | ||
``` | ||
\Resque_Failure::setBackend(\Talis\Resque\Failure\RedisMultipleQueues::class); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "talis/resque-multiple-failure-queues", | ||
"description": "Add-on for php-resque to allow multiple failure queues", | ||
"version": "0.1.0", | ||
"keywords": ["resque", "php-resque", "php"], | ||
"homepage": "https://github.com/talis/resque-multiple-failure-queues", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=5.5.9", | ||
"resque/php-resque": ">=1.3" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Talis\\Resque\\Failure\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Talis\Resque\Failure; | ||
|
||
/** | ||
* Redis backend for storing failed Resque jobs. | ||
* | ||
* @package Resque/Failure | ||
* @author Omar Qureshi <oq@talis.com> | ||
* @license http://www.opensource.org/licenses/mit-license.php | ||
*/ | ||
class RedisMultipleQueues implements \Resque_Failure_Interface | ||
{ | ||
const FAILED_SUFFIX = '_failed'; | ||
/** | ||
* Initialize a failed job class and save it (where appropriate). | ||
* | ||
* @param object $payload Object containing details of the failed job. | ||
* @param object $exception Instance of the exception that was thrown by the failed job. | ||
* @param object $worker Instance of Resque_Worker that received the job. | ||
* @param string $queue The name of the queue the job was fetched from. | ||
*/ | ||
public function __construct($payload, $exception, $worker, $queue) | ||
{ | ||
$data = new \stdClass(); | ||
$data->failed_at = strftime('%a %b %d %H:%M:%S %Z %Y'); | ||
$data->payload = $payload; | ||
$data->exception = get_class($exception); | ||
$data->error = $exception->getMessage(); | ||
$data->backtrace = explode("\n", $exception->getTraceAsString()); | ||
$data->worker = (string)$worker; | ||
$data->queue = $queue; | ||
$data = json_encode($data); | ||
\Resque::redis()->rpush($queue . self::FAILED_SUFFIX, $data); | ||
\Resque::redis()->sadd('failed_queues', $queue . self::FAILED_SUFFIX); | ||
\Resque_Stat::incr($queue . self::FAILED_SUFFIX); | ||
} | ||
} |