Skip to content

Commit

Permalink
Merge pull request #1 from talis/move-to-package
Browse files Browse the repository at this point in the history
Move into own package
  • Loading branch information
rsinger authored May 27, 2020
2 parents 4c42975 + a60dc5f commit c05196f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
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);
```
20 changes: 20 additions & 0 deletions composer.json
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/"
}
}
}
38 changes: 38 additions & 0 deletions src/RedisMultipleQueues.php
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);
}
}

0 comments on commit c05196f

Please sign in to comment.