2017 © Pedro Peláez
 

library mon-work-go

A simple mongo DB based work queue.

image

mead-steve/mon-work-go

A simple mongo DB based work queue.

  • Sunday, April 6, 2014
  • by MeadSteve
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

MonWorkGo

Simple work queue built on top of mongodb. A single collection in mongoDB is used to represent one work queue. A json payload is used to desribe the work which is then processed by a supplied callback., (*1)

master: Build Status develop: Build Status, (*2)

Installation

The easiest way to install this library is using composer. In your project's composer.json file add:, (*3)

{
    "require": {
        "mead-steve/mon-work-go": "2.0.*"
    }
}

Then run composer update., (*4)

Queueing up work

A mixed array of data describing your work can get queued for processing. This will be quick so you can respond to your user like a hero. This will create a collection called mainQueue in your mongoDB (if it doesn't already exist)., (*5)

$manager = new \MeadSteve\MonWorkGo\Manager($mongoDB);

$manager->getQueue("mainQueue")
    ->clearCompletedWork()      // Do a bit of house keeping
    ->addWork(["jobOne", 34])
    ->addWork([5, 7])
    ->addWork([8])
    ->addWork(["jobFour", "mead"])
    ->addWork(["jobFive", "beer"]);

Processing Work

Once your data has been nicely queued you can spend a bit more time processing it. To be honest you'll probably want to do a little more than echoing it but this should give you the idea. This script will run indefinitely and there's nothing stopping you having it running on multiple instances to share the load., (*6)

$manager = new \MeadSteve\MonWorkGo\Manager($mongoDB);

$manager->createWorker(
    "mainQueue",
    function ($payload) {
        echo "Hello. I'm working on: " . var_export($payload, true);
        return \MeadSteve\MonWorkGo\Worker::WORK_RESPONSE_SUCCESS;
    }
)->start();

Reporting on the progress of the work

The worker object can also be provided with a psr logger. In addition to sending debug messages to this logger the work function also gets passed the logger as the second argument so can report on its own progress., (*7)

$manager = (new \MeadSteve\MonWorkGo\Manager($mongoDB))->setLogger($logger);

$manager->createWorker(
    "mainQueue",
    function ($payload, \Psr\Log\LoggerInterface $log) {
        $log->info("Hello logger");
        $log->info("I should probably do some work");
        return \MeadSteve\MonWorkGo\Worker::WORK_RESPONSE_SUCCESS;
    }
)->start();

The Versions

06/04 2014

dev-master

9999999-dev

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

mongodb queue mongo message job processing work

06/04 2014

dev-develop

dev-develop

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

mongodb queue mongo message job processing work

06/04 2014

v2.0.0

2.0.0.0

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

mongodb queue mongo message job processing work

27/03 2014

v1.1.2

1.1.2.0

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

mongodb queue mongo message job processing work

27/03 2014

v1.1.1

1.1.1.0

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

27/03 2014

v1.1.0

1.1.0.0

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires

 

27/03 2014

v1.0.0

1.0.0.0

A simple mongo DB based work queue.

  Sources   Download

MIT

The Requires