2017 © Pedro Peláez
 

library queue

a job queue

image

tree6bee/queue

a job queue

  • Tuesday, February 27, 2018
  • by sh7ning
  • Repository
  • 1 Watchers
  • 4 Stars
  • 30 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 43 % Grown

The README.md

queue

A job queue (like laravel queue) based on beanstalkd(and other queue system), easy to dispatch job and handle job., (*1)

Keywords

queue, job, easy handle, job with timeout, delayed job, retry_after, given connection, given queue, given tube, memory limit,reload, (*2)

Installation

composer require "tree6bee/queue:~2.0", (*3)

Overview

Create Queue

use Tree6bee\Queue\Drivers\Beanstalkd;
use Tree6bee\Queue\Queue;

$queue = new Queue(new Beanstalkd($host, $port));

Create Job

<?php

use Tree6bee\Queue\Job;

class ExampleJob extends Job
{
    /**
     * @var string job queue name (beanstalkd tube)
     */
    public $queue = 'default';

    /**
     * The "time to run" for all pushed jobs. (beanstalkd ttr, timeout)
     *
     * @var int 允许 worker 执行的最大秒数,超时 job 将会被 release 到 ready 状态.
     */
    public $retry_after = 60;

    /**
     * The number of times the job may be attempted.
     *
     * @var int 最大尝试次数
     */
    public $tries = 1;

    /**
     * @var array
     */
    public $words;

    public function __construct(array $words)
    {
        $this->words = $words;
    }

    public function handle()
    {
        var_export($this->words);

        var_dump($this->retry_after, $this->tries);

        // throw new \Exception('handle job with error...lol ^_^');
    }
}

specifying job queue by defining $queue , specifying Max Job Attempts by defining $tries , specifying timeout Values by defining $retry_after ., (*4)

Dispatch Job

$queue->push(new ExampleJob(['i', 'love', 'china']));

of cause, you can dispatch job later (push a delayed job) :, (*5)

$queue->later(60, new ExampleJob(['i', 'love', 'china']));

Process Job

$worker = new Worker($queue);

$worker->daemon();

Note: $worker->daemon() is blocking., (*6)

by default, the worker will will listen the tube named default, you can specifying worker queue (beanstalkd tube) like :, (*7)

$queueTube = 'sendEmail';
$worker = new Worker($queue, $queueTube);

$worker->daemon();

you can specifying worker with sleep time while there is no job, and memoryLimit, like :, (*8)

$sleep = 60;
$memoryLimit = 128;

$queueTube = 'sendEmail';
$worker = new Worker($queue, $queueTube);

$worker->daemon($sleep, $memoryLimit);

Notice, if you want reload queue worker, you should implement queueShouldRestartmethod on class Tree6bee\Queue\Worker., (*9)

Recommend

it's highly recommended that extends Tree6bee\Queue\Worker, and you should implements these methods: logProcessError, handleWithObj, queueShouldRestart., (*10)

Other

the queue package can work on other queue system, you should implements these interface Tree6bee\Queue\Drivers\Jobs\JobInterface, Tree6bee\Queue\Drivers\QueueInterface., (*11)

Example

Todo

  • add some useful command, like clearn queue job or kick buried job, etc.

The Versions

27/02 2018

dev-master

9999999-dev

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.7

2.0.7.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.6

2.0.6.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.5

2.0.5.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.4

2.0.4.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.3

2.0.3.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

26/01 2018

2.0.2

2.0.2.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

09/01 2018

2.0.1

2.0.1.0

a job queue

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx

08/01 2018

2.0.0

2.0.0.0

the ctx support library

  Sources   Download

MIT

The Requires

 

The Development Requires

queue context tree6bee ctx