Skip to content

Commit

Permalink
Version 2, created dedicated worker sub-classes and add support for m…
Browse files Browse the repository at this point in the history
…ore Laravel versions (#10)

* Add copied dedicated worker class and update batch runner to use it

* Update worker and batch runner to use the same worker options class

* Update comments and fix class compatibility for stop if necessary method

* Fix sytax error and work options class compatability

* Update application container when building worker to support maintenance mode

* Update PHP and Laravel verion numbers in composer to be more accurate

* Minor doc comment update

* Switch to strict types being enabled for all PHP files

* Fix to use batch worker interface for bindings

* Fix interface name

* Minor white space change

* Fix another spelling of our new batch worker interface

* Copy laravel work command

* Fix batch command constructor differences

* Fix worker options constructor

* Fix missing stop when empty param for worker options

* Bug fix and attempt to workaround pcre.jit issues

* Clean up laravel classes and copy required Looping class

* Added workoptions laravel copy and updated and fixed use paths

* Update incorrect usage for batch options vs work options

* Fix work option constructor params and construction

* Fix syntax error

* Change to WorkOptions type hinting by default

* Fix using laravel workoptions class when it should be ours

* Fix batch command name

* Minor formatting changes

* Remove not required command constructor that should just inherit its constructor

* Fix casting and return types

* Update app spawn to verion 1.5

* Minor test return type update

* Remove void keyword for older php 7 version support

* Update and adapt prcessing and flow to new structure and get tests to pass

* add function exist check for pcntl extension package

* Update larvel version to be 5.5 to 7.0 in composer and CI

* Optimize PHP version tests

* Update README PHP and Laravel version support
  • Loading branch information
JFossey authored Jul 30, 2020
1 parent 7f8b9db commit c06eaf1
Show file tree
Hide file tree
Showing 19 changed files with 1,471 additions and 221 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@ cache:

matrix:
include:
# - php: 5.6
# env: ILLUMINATE_VERSION=5.3.*
# - php: 5.6
# env: ILLUMINATE_VERSION=5.4.*
- php: 7.0
env: ILLUMINATE_VERSION=5.3.*
- php: 7.0
env: ILLUMINATE_VERSION=5.4.*
- php: 7.0
env: ILLUMINATE_VERSION=5.5.*
- php: 7.1
env: ILLUMINATE_VERSION=5.3.*
- php: 7.1
env: ILLUMINATE_VERSION=5.4.*
- php: 7.1
env: ILLUMINATE_VERSION=5.5.*
- php: 7.3
env: ILLUMINATE_VERSION=5.6.*
- php: 7.2
env: ILLUMINATE_VERSION=5.7.*
- php: 7.3
env: ILLUMINATE_VERSION=5.8.*
- php: 7.3
env: ILLUMINATE_VERSION=6.*
- php: 7.4
env: ILLUMINATE_VERSION=7.*

# instal our framework version
before_install:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Laravel Artisan commands that make it easy to run job queues using the Scheduler

This is ideal for shared hosting or situations where you are not fully in control of the services or management of your hosting infrastructure and all you have access to is a Cron.

## Versions
## Versions Support Matrix

**Confirmed to be working:**
| QueueButler | PHP | Laravel |
| :---------: | :-------: | :-------: |
| 1.4 | 5.6 - 7.3 | 5.3 - 5.6 |
| 2.0 | 7.0 - 7.4 | 5.5 - 7.x |

* Laravel 5.3
* Laravel 5.4
* Laravel 5.5
* Laravel 5.6
**Note:** The PHP version support corresponds with the Laravel PHP support.

## Install

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
}
],
"require": {
"php": "~5.6|~7.0",
"laravel/framework": "5.*"
"php": "~7.0",
"laravel/framework": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "~5.7",
"squizlabs/php_codesniffer": "^2.3",
"doctrine/dbal": "^2.5",
"web-chefs/laravel-app-spawn": "^1.0"
"web-chefs/laravel-app-spawn": ">=1.5"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
Expand Down
45 changes: 19 additions & 26 deletions src/BatchCommand.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php

declare(strict_types=1);

namespace WebChefs\QueueButler;

// Package
use WebChefs\QueueButler\BatchRunner;
use WebChefs\QueueButler\BatchOptions;

// Framework
use Illuminate\Queue\Console\WorkCommand;
use WebChefs\QueueButler\Laravel\WorkCommand;
use WebChefs\QueueButler\Laravel\WorkerOptions;

class BatchCommand extends WorkCommand
{

/**
* The console command name.
*
Expand All @@ -20,12 +19,13 @@ class BatchCommand extends WorkCommand
protected $signature = 'queue:batch
{connection? : The name of the queue connection to work}
{--queue= : The names of the queues to work}
{--delay=0 : Amount of time to delay failed jobs}
{--stop-when-empty : Stop when the queue is empty}
{--delay=0 : The number of seconds to delay failed jobs}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=0 : Number of times to attempt a job before logging it failed}
{--tries=1 : Number of times to attempt a job before logging it failed}
{--time-limit=60 : The max time in seconds the batch should run for}
{--job-limit=100 : The maximum number of Jobs that the batch should process}';

Expand All @@ -36,25 +36,14 @@ class BatchCommand extends WorkCommand
*/
protected $description = 'Processing jobs on the queue as single once off batch';

/**
* Create a new queue listen command.
*
* @param \Illuminate\Queue\Worker $worker
* @return void
*/
public function __construct(BatchRunner $worker)
{
parent::__construct($worker);
}

/**
* Execute the console command.
*
* @return void
* @return integer
*/
public function fire()
public function handle()
{
if ($this->downForMaintenance()) {
if ($this->downForMaintenance() && $this->option('once')) {
return $this->worker->sleep($this->option('sleep'));
}

Expand All @@ -71,28 +60,32 @@ public function fire()
// connection being run for the queue operation currently being executed.
$queue = $this->getQueue($connection);

$this->runWorker($connection, $queue);
return $this->runWorker(
$connection, $queue
);
}

/**
* Run the worker instance.
*
* @param string $connection
* @param string $queue
* @return array
*
* @return integer
*/
protected function runWorker($connection, $queue)
{
$this->worker->setCache($this->laravel['cache']->driver());

return $this->worker->batch( $connection, $queue, $this->gatherWorkerOptions() );
}

/**
* Gather all of the queue worker options as a single object.
*
* @return \Illuminate\Queue\WorkerOptions
* @return BatchOptions
*/
protected function gatherWorkerOptions()
protected function gatherWorkerOptions(): WorkerOptions
{
return new BatchOptions(
$this->option('delay'),
Expand All @@ -101,9 +94,9 @@ protected function gatherWorkerOptions()
$this->option('sleep'),
$this->option('tries'),
$this->option('force'),
$this->option('stop-when-empty'),
$this->option('time-limit'),
$this->option('job-limit')
);
}

}
46 changes: 28 additions & 18 deletions src/BatchOptions.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

declare(strict_types=1);

namespace WebChefs\QueueButler;

// Framework
use Illuminate\Queue\WorkerOptions;
// Package
use WebChefs\QueueButler\Laravel\WorkerOptions;

class BatchOptions extends WorkerOptions
{

/**
* The maximum number of seconds a batch should run for.
*
Expand All @@ -24,28 +25,37 @@ class BatchOptions extends WorkerOptions
/**
* Create a new worker options instance.
*
* @param int $delay
* @param int $memory
* @param int $timeout
* @param int $sleep
* @param int $maxTries
* @param bool $force
* @param int $timelimit
* @param int $jobLimit
* @param int $delay
* @param int $memory
* @param int $timeout
* @param int $sleep
* @param int $maxTries
* @param bool $force
* @param bool $stopWhenEmpty
* @param integer $timeLimit
* @param integer $jobLimit
*
* @return void
*/
public function __construct($delay = 0,
$memory = 128,
$timeout = 60,
$sleep = 3,
$maxTries = 0,
$maxTries = 1,
$force = false,
$stopWhenEmpty = false,
$timeLimit = 60,
$jobLimit = 100)
{
parent::__construct($delay, $memory, $timeout, $sleep, $maxTries, $force);

$this->timeLimit = $timeLimit;
$this->jobLimit = $jobLimit;
parent::__construct((int)$delay,
(int)$memory,
(int)$timeout,
(int)$sleep,
(int)$maxTries,
(bool)$force,
(bool)$stopWhenEmpty);

$this->timeLimit = (int)$timeLimit;
$this->jobLimit = (int)$jobLimit;
}

}
}
Loading

0 comments on commit c06eaf1

Please sign in to comment.