Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #243 from koenkivits/feature/v3
Browse files Browse the repository at this point in the history
v3 final
  • Loading branch information
koenkivits authored Dec 2, 2021
2 parents 37128df + 5e6c397 commit a84ee18
Show file tree
Hide file tree
Showing 90 changed files with 846 additions and 152 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml → .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
strategy:
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
dependencies:
Expand All @@ -24,13 +23,22 @@ jobs:
steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Run PHPUnit"
run: "vendor/bin/phpunit --configuration phpunit.xml.dist"
run: "composer test"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ or [SlmQueueDoctrine](https://github.com/JouwWeb/SlmQueueDoctrine)

Requirements
------------
* PHP >= 7.3
* PHP >= 7.4
* [laminas-servicemanager >= 3.3.1](https://github.com/laminas/laminas-servicemanager)


Expand Down Expand Up @@ -134,9 +134,12 @@ class MyController extends AbstractActionController
```

Now the above code lets you insert jobs in a queue, but then you need to spin up a worker which can process these jobs.
Giving an example with beanstalkd and a queue which you called "default", you can start a worker with this command:

php public/index.php queue beanstalkd default
SlmQueue integrates with [`laminas-cli`](https://github.com/laminas/laminas-servicemanager) for command line usage. You can start up a worker for queue "default" with the following command:

```sh
$ vendor/bin/laminas slm-queue:start default
```

Contributing
------------
Expand Down
23 changes: 23 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ugrade to 3.0

This release adds support for PHP 8.0.

## BC BREAK: `laminas-cli` replaces `laminas-mvc-console`

The CLI can now be invoked with the following command:

```sh
vendor/bin/laminas slm-queue:start
```

## BC BREAK: Dropped support for PHP 7.3

SlmQueue now requires at least PHP 7.4.

## BC BREAK: Added `QueueInterface::getWorkerName()`

Classes implementing `QueueInterface` are now required to indicate which worker should be used to process the queue. This change will likely only affect you if you use a custom delegator for your queue.

## BC BREAK: Workers are now managed by `WorkerPluginManager`

Workers (and their aliases and delegators) should now be configured under `slm_queue.worker_manager` instead of `service_manager` (Laminas) or `dependencies` (Mezzio).
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ~8.0",
"laminas/laminas-eventmanager": "^3.3",
"laminas/laminas-servicemanager": "^3.6",
"laminas/laminas-stdlib": "^3.3"
"laminas/laminas-stdlib": "^3.3",
"laminas/laminas-cli": "^1.1.1"
},
"require-dev": {
"laminas/laminas-mvc": "^3.2",
Expand All @@ -45,7 +46,8 @@
"laminas/laminas-log": "^2.13",
"laminas/laminas-i18n": "^2.11",
"laminas/laminas-config": "^3.4",
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.3",
"squizlabs/php_codesniffer": "3.*"
},
"suggest": {
"slm/queue-sqs": "If you are using Amazon SQS",
Expand All @@ -69,11 +71,16 @@
},
"autoload-dev": {
"psr-4": {
"SlmQueueTest\\": "tests/"
"SlmQueueTest\\": "tests/src"
}
},
"scripts": {
"cs-check": "phpcs",
"cs-fix": "phpcbf"
"cs-fix": "phpcbf",
"test": [
"phpunit",
"@composer test --working-dir=tests/integration/laminas",
"@composer test --working-dir=tests/integration/mezzio"
]
}
}
18 changes: 18 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

use Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory;
use SlmQueue\Command\StartWorkerCommand;
use SlmQueue\Factory\JobPluginManagerFactory;
use SlmQueue\Factory\QueueControllerPluginFactory;
use SlmQueue\Factory\QueuePluginManagerFactory;
use SlmQueue\Factory\StrategyPluginManagerFactory;
use SlmQueue\Factory\WorkerPluginManagerFactory;
use SlmQueue\Job\JobPluginManager;
use SlmQueue\Queue\QueuePluginManager;
use SlmQueue\Strategy\AttachQueueListenersStrategy;
Expand All @@ -18,13 +21,23 @@
use SlmQueue\Strategy\ProcessQueueStrategy;
use SlmQueue\Strategy\StrategyPluginManager;
use SlmQueue\Strategy\WorkerLifetimeStrategy;
use SlmQueue\Worker\WorkerPluginManager;

return [
'service_manager' => [
'factories' => [
JobPluginManager::class => JobPluginManagerFactory::class,
StrategyPluginManager::class => StrategyPluginManagerFactory::class,
QueuePluginManager::class => QueuePluginManagerFactory::class,
WorkerPluginManager::class => WorkerPluginManagerFactory::class,

StartWorkerCommand::class => ReflectionBasedAbstractFactory::class,
],
],

'laminas-cli' => [
'commands' => [
'slm-queue:start' => StartWorkerCommand::class,
],
],

Expand Down Expand Up @@ -67,6 +80,11 @@
*/
'queue_manager' => [],

/**
* Worker manager configuration
*/
'worker_manager' => [],

/**
* Strategy manager configuration
*/
Expand Down
28 changes: 14 additions & 14 deletions docs/2.Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ by using a factory from one of these systems. A queue is defined in the `queue_m
a queue named "default" is defined.

```php
'slm_queue' => array(
'queue_manager' => array(
'factories' => array(
'slm_queue' => [
'queue_manager' => [
'factories' => [
'default' => 'SlmQueueBeanstalkd\Factory\BeanstalkdQueueFactory'
),
),
),
],
],
],
```

If you get this queue from the queue manager, SlmQueue will configure the instance completely for you and you are ready
Expand Down Expand Up @@ -56,16 +56,16 @@ Jobs
Jobs are defined in a similar fashion. The `job_manager` key is available for this configuration.

```php
'slm_queue' => array(
'job_manager' => array(
'factories' => array(
'slm_queue' => [
'job_manager' => [
'factories' => [
'MyModule\Job\SendEmailJob' => 'MyModule\Factory\SendEmailJobFactory',
),
'invokables' => array(
],
'invokables' => [
'MyModule\Job\PrintHelloWorldJob' => 'MyModule\Job\PrintHelloWorldJob',
),
),
),
],
],
],
```

It is not required to use factories for all jobs. If a job does not need any dependency, you can define the job as an
Expand Down
29 changes: 14 additions & 15 deletions docs/3.Jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class MyController extends AbstractActionController
// Do some work

$job = $this->jobManager->get('MyModule\Job\SendEmailJob');
$job->setContent(array(
$job->setContent([
'to' => '[email protected]',
'subject' => 'Registration completed',
'message' => 'Hi bob, you just registered for our website! Welcome!'
));
]);

$this->queue->push($job);
}
Expand Down Expand Up @@ -143,13 +143,13 @@ class SendEmailJobFactory implements FactoryInterface
The last step is to register this factory for the above job. Note that in order for this to work the service should be registered with the FQCN of the job class as its identifier.

```php
'slm_queue' => array(
'job_manager' => array(
'factories' => array(
'slm_queue' => [
'job_manager' => [
'factories' => [
'MyModule\Job\SendEmailJob' => 'MyModule\Factory\SendEmailJobFactory',
),
),
)
],
],
]
```

Jobs with binary payload
Expand Down Expand Up @@ -237,11 +237,11 @@ class MyController extends AbstractActionController
// Do some work

$this->queue('default')
->push('MyModule\Job\SendEmailJob', array(
->push('MyModule\Job\SendEmailJob', [
'to' => '[email protected]',
'subject' => 'Registration completed',
'message' => 'Hi bob, you just registered for our website! Welcome!'
));
]);
}
}
```
Expand All @@ -262,15 +262,14 @@ class MyController extends AbstractActionController

// Push two jobs into the same queue
$this->queue('default')
->push('MyModule\Job\SendEmailJob', array(
->push('MyModule\Job\SendEmailJob', [
'to' => '[email protected]',
'subject' => 'Registration completed',
'message' => 'Hi bob, you just registered for our website! Welcome!'

))
->push('MyModule\Job\TweetJob', array(
])
->push('MyModule\Job\TweetJob', [
'message' => 'We have a new user registered, his name is bob!'
));
]);

// Push into anther queue
$this->queue('background')
Expand Down
2 changes: 1 addition & 1 deletion docs/5.Workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After [queues are configured](2.Configuration.md), [jobs classes are written](3.
must be popped out by a worker to be executed. This is done, as explained in the [introduction](1.Introduction.md), by
workers. A worker for SlmQueue is a class implementing the `SlmQueue\Worker\WorkerInterface`.

A worker is started by by calling its `processQueue($queue, array $options = array())` method. The `$queue` parameter is
A worker is started by by calling its `processQueue($queue, array $options = [])` method. The `$queue` parameter is
a string and should be the service name of the queue as registered in the queue plugin manager. The `$options` parameter
is an optional array which is directly passed on to the `pop()` method of the queue. This can contain flags specifically
for the different queue implementations.
Expand Down
Loading

0 comments on commit a84ee18

Please sign in to comment.