Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sfcod/jobqueue
https://github.com/sfcod/jobqueue
async-queue php queue symfony symfony-bundle
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sfcod/jobqueue
- Owner: sfcod
- Created: 2018-02-20T15:21:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-16T20:08:40.000Z (3 months ago)
- Last Synced: 2024-12-10T04:10:24.637Z (12 days ago)
- Topics: async-queue, php, queue, symfony, symfony-bundle
- Language: PHP
- Size: 129 KB
- Stars: 15
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Job Queue Bundle for Symfony
======================================================[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sfcod/jobqueue/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sfcod/jobqueue/?branch=master)[![Code Climate](https://codeclimate.com/github/sfcod/jobqueue/badges/gpa.svg)](https://codeclimate.com/github/sfcod/jobqueue)
Provides async queues implementation for Symfony (using mongodb as main storage).
#### Supported drivers (storages):
- [MongoDB](Doc/mongodb.md)
- [Redis](Doc/redis.md)
- [Custom](Doc/custom.md)#### Config:
Register the bundle config and all available "Jobs"
```yaml
sfcod_queue:
drivers:
redis: 'SfCod\QueueBundle\Connector\RedisConnector'
connections:
default: { driver: 'redis', collection: 'queue_jobs', queue: 'default', expire: 360, limit: 2 }services:
# _instanceof:
# SfCod\QueueBundle\Base\JobInterface:
# tags: ['sfcod.jobqueue.job']
App\Job\:
resource: '../src/Job/*'
tags: ['sfcod.jobqueue.job']
```#### Adding jobs to the queue:
Create your own "job" which implements SfCod\QueueBundle\Base\JobInterface and run it:
```php
public function someFunc(JobQueue $jobQueue) {
$data = [...];
$jobQueue->push(YourJob::class, $data);
}
```
where $data is a payload for your job#### Commands:
Run worker daemon with console command:
```php
$ php bin/console job-queue:work
$ php bin/console job-queue:retry --id=
$ php bin/console job-queue:run-job
```Where:
- work - command to run daemon in loop;
- retry - command to move all failed jobs back into queue, can be used with --id param to retry only single job
- run-job - command to run single job by id#### Available events:
```php
'job_queue_worker.raise_before_job': SfCod\QueueBundle\Event\JobProcessingEvent;
'job_queue_worker.raise_after_job': SfCod\QueueBundle\Event\JobProcessedEvent;
'job_queue_worker.raise_exception_occurred_job': SfCod\QueueBundle\Event\JobExceptionOccurredEvent;
'job_queue_worker.raise_failed_job': SfCod\QueueBundle\Event\JobFailedEvent;
'job_queue_worker.stop': SfCod\QueueBundle\Event\WorkerStoppingEvent;
```#### Configurable services list (with default parameters):
##### JobQueue:
```yaml
SfCod\QueueBundle\Service\JobQueue:
public: true
arguments:
- '@SfCod\QueueBundle\Service\QueueManager'
```
SfCod\QueueBundle\Service\JobQueue: main job queue service##### Worker
```yaml
SfCod\QueueBundle\Worker\Worker:
arguments:
- '@SfCod\QueueBundle\Service\QueueManager'
- '@SfCod\QueueBundle\Service\JobProcess'
- '@SfCod\QueueBundle\Failer\FailedJobProviderInterface'
- '@SfCod\QueueBundle\Handler\ExceptionHandlerInterface'
- '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
```
SfCod\QueueBundle\Worker\Worker: async worker for "work" command##### JobProcess
```yaml
SfCod\QueueBundle\Service\JobProcess:
arguments:
- 'console'
- '%kernel.project_dir%/bin'
- 'php'
- ''
```
JobProcess: default config for jobs command processor in async queues, where:
- 'console' - name of console command
- '%kernel.project_dir%/bin' - path for console command
- 'php' - binary script
- '' - binary script arguments##### Connector
```yaml
SfCod\QueueBundle\Connector\ConnectorInterface:
class: SfCod\QueueBundle\Connector\RedisConnector
arguments:
- '@SfCod\QueueBundle\Base\JobResolverInterface'
- '@SfCod\QueueBundle\Base\RedisDriver'
```
SfCod\QueueBundle\Connector\ConnectorInterface: connector for queues' database##### Failer
```yaml
SfCod\QueueBundle\Failer\FailedJobProviderInterface:
class: SfCod\QueueBundle\Failer\RedisFailedJobProvider
arguments:
- '@SfCod\QueueBundle\Service\RedisDriver'
- 'queue_jobs_failed'
```
SfCod\QueueBundle\Failer\FailedJobProviderInterface: storage for failed jobs##### Job resolver
```yaml
SfCod\QueueBundle\Base\JobResolverInterface:
class: SfCod\QueueBundle\Service\JobResolver
arguments:
- '@Symfony\Component\DependencyInjection\ContainerInterface'
```
SfCod\QueueBundle\Base\JobResolverInterface: resolver for jobs, it builds job using job's display name, for default jobs fetches from container as a public services.##### Exception handler
```yaml
SfCod\QueueBundle\Handler\ExceptionHandlerInterface:
class: SfCod\QueueBundle\Handler\ExceptionHandler
arguments:
- '@Psr\Log\LoggerInterface'
```
SfCod\QueueBundle\Handler\ExceptionHandlerInterface: main exception handler, used for logging issues##### Testing:
You can run tests using prepared configuration xml file:
```php
php bin/phpunit --configuration ./vendor/sfcod/jobqueue/phpunit.xml.dist --bootstrap ./vendor/autoload.php
```