Commit 4e6cc229 authored by Fady Khalife's avatar Fady Khalife Committed by Jens Segers

Fixes #789 (#792)

* Fixes #789

* StyleCI fixes

* StyleCI fixes

* StyleCI fixes
parent 87d8eedd
......@@ -262,6 +262,21 @@ If you want to use MongoDB as your database backend, change the the driver in `c
],
```
If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
```php
'failed' => [
'database' => 'mongodb',
'table' => 'failed_jobs',
],
```
And add the service provider in `config/app.php`:
```php
Jenssegers\Mongodb\MongodbQueueServiceProvider::class,
```
### Sentry
If you want to use this library with [Sentry](https://cartalyst.com/manual/sentry), then check out https://github.com/jenssegers/Laravel-MongoDB-Sentry
......
<?php namespace Jenssegers\Mongodb;
use Illuminate\Queue\QueueServiceProvider;
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
class MongodbQueueServiceProvider extends QueueServiceProvider
{
/**
* Register the failed job services.
*
* @return void
*/
protected function registerFailedJobServices()
{
// Add compatible queue failer if mongodb is configured.
if (config('queue.failed.database') == 'mongodb') {
$this->app->singleton('queue.failer', function ($app) {
return new MongoFailedJobProvider($app['db'], config('queue.failed.database'), config('queue.failed.table'));
});
} else {
parent::registerFailedJobServices();
}
}
}
<?php namespace Jenssegers\Mongodb\Queue\Failed;
use Carbon\Carbon;
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
class MongoFailedJobProvider extends DatabaseFailedJobProvider
{
/**
* Log a failed job into storage.
*
* @param string $connection
* @param string $queue
* @param string $payload
*
* @return void
*/
public function log($connection, $queue, $payload)
{
$failed_at = Carbon::now()->getTimestamp();
$this->getTable()->insert(compact('connection', 'queue', 'payload', 'failed_at'));
}
/**
* Get a list of all of the failed jobs.
*
* @return array
*/
public function all()
{
$all = $this->getTable()->orderBy('_id', 'desc')->get();
$all = array_map(function ($job) {
$job['id'] = (string) $job['_id'];
return $job;
}, $all);
return $all;
}
/**
* Get a single failed job.
*
* @param mixed $id
* @return array
*/
public function find($id)
{
$job = $this->getTable()->find($id);
$job['id'] = (string) $job['_id'];
return $job;
}
/**
* Delete a single failed job from storage.
*
* @param mixed $id
* @return bool
*/
public function forget($id)
{
return $this->getTable()->where('_id', $id)->delete() > 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment