yiisoft / yii2-queue

Yii2 Queue Extension. Supports DB, Redis, RabbitMQ, Beanstalk and Gearman
BSD 3-Clause "New" or "Revised" License
1.07k stars 295 forks source link

Beanstalkd bury jobs #78

Open lordlele opened 7 years ago

lordlele commented 7 years ago

Hi, I'm asking once more for this. As you can see #62 was closed without a real answer, because buring jobs is part of Beanstalkd core and it's a common practice that all Beanstalkd client implements (like Pheanstalk). I've clearly stated why bury jobs can be useful and that behavior can be configurable (delete failed jobs or otherwise bury failed jobs).

Did you maybe accept a PR for this?

tonydspaniard commented 7 years ago

Maybe the way to allow developers to process code out of the internally provided by their contracts (interfaces) and API, is to be able to access its internal driver (i.e. https://github.com/yiisoft/yii2-queue/blob/master/src/drivers/beanstalk/Queue.php#L138) so, if a project fails x amount of times, developer is able to actually do whatever he wishes (bury, remove, etc...) not just with beanstalkd but with the rest of the storage systems provided.

I did something like that on one of my libraries: https://github.com/2amigos/mailer-library/blob/master/src/Queue/Backend/QueueStoreAdapterInterface.php#L14

lordlele commented 7 years ago

I didn't say that behavior must be forced, but only configurable. If I want to delete failed jobs and then search errors in logs, I can do that. But, if I want to bury jobs to later inspection, fix and re-enqueue, I want to be able to do that.

SamMousa commented 6 years ago

I think you can already do this:

Specifically the last 2 points are interesting.

  1. Implement the job object that buries the job as soon as it starts executing.
  2. Set attempts to anything larger than 1.
  3. Throw an exception during job execution.

Since the job was buried it will not be re queued, but it can still be deleted in case the job succeeds.

@tonydspaniard As far as I can tell, you already have access to the queue driver. This is because the magic getter in Yii exposes protected getters...

if ($queue instanceof yii\queue\beanstalk\Queue) {
    /** @var Pheanstalk\Pheanstalk $pheanstalk */
    $pheanstalk = $queue->pheanstalk;
}

This is of course not a very nice solution since it depends on non-public APIs..