Giter VIP home page Giter VIP logo

queue-pheanstalk's Introduction

pmg/queue-pheanstalk

A driver for pmg/queue backed by Pheanstalk and Beanstalkd.

See the pmg/queue readme for the documentation of how the queue system as a whole works.

See the examples directory for examples of how to glue everything together.

Quick Example

Pheanstalk is a PHP library for interacting with Beanstalkd. PheanstalkDriver lets you take advantage of Beanstalkd as a queue backend.

use Pheanstalk\Pheanstalk;
use PMG\Queue\DefaultConsumer;
use PMG\Queue\Driver\PheanstalkDriver;
use PMG\Queue\Serializer\NativeSerializer;
use PMG\Queue\Serializer\SigningSerializer;

// ...

$serilizer = new NativeSerializer('this is the secret key');

$driver = new PheanstalkDriver(new \Pheanstalk\Pheanstalk('localhost'), $serializer, [
    // how long easy message has to execute in seconds
    'ttr'               => 100,

    // the "priority" of the message. High priority messages are
    // consumed first.
    'priority'          => 1024,

    // The delay between inserting the message and when it
    // becomes available for consumption
    'delay'             => 0,

    // The ttr for retries jobs
    'retry-ttr'         => 100,

    // the priority for retried jobs
    'retry-priority'    => 1024,

    // When jobs fail, they are "burieds" in beanstalkd with this priority
    'fail-priority'     => 1024,

    // A call to `dequeue` blocks for this number of seconds. A zero or
    // falsy value will block until a job becomes available
    'reserve-timeout'   => 10,
]);

// $handler instanceof PMG\Queue\MessageHandler
$consumer = new DefaultConsumer($driver, $handler);

Dealing with Failed Messages

By default, PheanstalkDriver will bury any message passed to PheanstalkDriver::fail. This is, generally, a good thing if there are no other accountability measures around your queue system.

That said, pmg/queue does nothing for you regarding kicking jobs back to a ready state. If there are other accountability measures around your queue implementation and you'd rather just delete failed messages after they've been retried, use a different FailureStrategy.

use Pheanstalk\Pheanstalk;
use PMG\Queue\DefaultConsumer;
use PMG\Queue\Driver\PheanstalkDriver;
use PMG\Queue\Driver\Pheanstalk\DeleteFailureStrategy;
use PMG\Queue\Serializer\NativeSerializer;

// ...

$serilizer = new NativeSerializer('this is the secret key');
$failureStrategy = new DeleteFailureStrategy();

$driver = new PheanstalkDriver(new \Pheanstalk\Pheanstalk('localhost'), $serializer, [
    // as above
], $failureStrategy);

// $handler instanceof PMG\Queue\MessageHandler
$consumer = new DefaultConsumer($driver, $handler);

Feel free to implement PMG\Queue\Driver\Pheanstalk\FailureStrategy if a different solution is needed.

queue-pheanstalk's People

Contributors

chrisguitarguy avatar webcu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

queue-pheanstalk's Issues

Use the `stats-job` API to Track Retries

Rather than deleting and inserting the job again with an incremented retry count, the driver can serialize the message only and use the reserved count to track how many times it was retried.

Support a Pluggable Way to Deal with Failed Messages

Right now failed messages that are not retried are buried. This okay in most cases, but a queue under heavy workload might eat a ton of memory with buried messages over time.

We should provide a way to plugin in something that does different things with failed messages -- probably a simple strategy pattern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.