Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] an implementation of FailedJobProviderInterface #367

Closed
ghost opened this issue Nov 22, 2014 · 1 comment
Closed

[Proposal] an implementation of FailedJobProviderInterface #367

ghost opened this issue Nov 22, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 22, 2014

Laravel is having trouble manipulate failed jobs

for example:

artisan queue:failedwill display all failed jobs but unfortunately, there is a field "failed_at".

It has to be a string when displaying "failed_at" but it's a Date in fact.

Here is my immature implementation

<?php namespace My\ServiceProviders;

use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Queue\Failed\FailedJobProviderInterface;
class MongoFailedJobProvider implements FailedJobProviderInterface {

    /**
     * The connection resolver implementation.
     *
     * @var \Illuminate\Database\ConnectionResolverInterface
     */
    protected $resolver;

    /**
     * The database connection name.
     *
     * @var string
     */
    protected $database;

    /**
     * The database table.
     *
     * @var string
     */
    protected $table;

    /**
     * Create a new database failed job provider.
     *
     * @param  \Illuminate\Database\ConnectionResolverInterface  $resolver
     * @param  string  $database
     * @param  string  $table
     * @return void
     */
    public function __construct(ConnectionResolverInterface $resolver, $database, $table)
    {
        $this->table = $table;
        $this->resolver = $resolver;
        $this->database = $database;
    }

    /**
     * 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 = date('Y-m-d H:i:s');

        $this->getCollection()->insert(compact('connection', 'queue', 'payload', 'failed_at'));
    }

    /**
     * Get a list of all of the failed jobs.
     *
     * @return array
     */
    public function all()
    {
        return $this->getCollection()->orderBy('failed_at', 'desc')->get();

    }

    /**
     * Get a single failed job.
     *
     * @param  mixed  $id
     * @return array
     */
    public function find($id)
    {
        return $this->getCollection()->where('_id', $id)->first();
    }

    /**
     * Delete a single failed job from storage.
     *
     * @param  mixed  $id
     * @return bool
     */
    public function forget($id)
    {
        return $this->getCollection()->where('_id', $id)->delete() > 0;
    }

    /**
     * Flush all of the failed jobs from storage.
     *
     * @return void
     */
    public function flush()
    {
        $this->getCollection()->delete();
    }

    /**
     * Get a new query builder instance for the table.
     *
     * @return \Illuminate\Database\Query\Builder
     */
    protected function getCollection()
    {
        return $this->resolver->connection($this->database)->collection($this->table);
    }
}
@robsoncombr
Copy link

I'm facing this problem.

It sends the failed jobs to mongodb, however artisan fails:

$ php artisan queue:failed
[ErrorException]
strstr() expects parameter 1 to be string, array given

How do I implement the workaround?

Is this going to be fixed?

Thank you,

Robson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants