idci / task-bundle
Symfony task bundle
Installs: 450
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 21
Type:symfony-bundle
Requires
- php: >=5.3.9
- doctrine/doctrine-bundle: ~1.2
- doctrine/mongodb: ~1.1
- doctrine/mongodb-odm: ~1.0
- doctrine/mongodb-odm-bundle: ~3.0
- doctrine/orm: ~2.2,>=2.2.3
- friendsofsymfony/rest-bundle: ~1.5
- idci/asset-loader-bundle: ~1.0
- mtdowling/cron-expression: ~1.2
- php-amqplib/rabbitmq-bundle: ~1.6
- ramsey/uuid: ~3.0
- symfony/framework-bundle: ~2.3
- symfony/monolog-bundle: ~2.11.3
- symfony/twig-bundle: ~2.8
- twig/twig: ~1.0
Requires (Dev)
- phpunit/phpunit: ~5.7
- symfony/symfony: ^2.3
- dev-master
- 2.5.x-dev
- v2.5.4
- v2.5.3
- v2.5.2
- 2.5.1
- v2.5.0
- 2.4.x-dev
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- 2.3.x-dev
- v2.3.16
- v2.3.15
- v2.3.14
- v2.3.13
- v2.3.12
- v2.3.11
- v2.3.10
- v2.3.9
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- 2.3.2
- v2.3.1
- v2.3.0
- v2.2.2
- v2.2.1
- v2.2
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1
- v2.0
- v1.3.0
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1
- 1.0.x-dev
- v1.0.1
- v1.0.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/karma-6.3.16
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/chownr-1.1.4
- dev-dependabot/npm_and_yarn/tar-4.4.19
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/codemirror-5.58.2
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/handlebars-3.0.8
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/decompress-4.2.1
- dev-dependabot/npm_and_yarn/bootstrap-vue-2.0.0-rc.12
- dev-dependabot/npm_and_yarn/yarn-1.22.0
- dev-dependabot/npm_and_yarn/bower-1.8.8
- dev-dependabot/npm_and_yarn/bootstrap-4.3.1
- dev-dependabot/npm_and_yarn/extend-3.0.2
- dev-dependabot/npm_and_yarn/mixin-deep-1.3.2
This package is auto-updated.
Last update: 2024-10-30 01:31:49 UTC
README
The purpose of this bundle is to add an easy way to asynchronously process CPU-intensive scripts. You might be used to cron jobs to solve this kind of problems. This bundle use RabbitMq which solve those issues more efficiently and more effectively. A CPU-intensive script is called an action. To keep traces on actions, this bundle uses monolog to store the action logs in MongoDB. If you want to understand how this bundle works, you need the basics about RabbitMQ.
- Introduction
- Installation
- Run the tests
- How to create an extract rule service
- How to create an action service
- How to create a task configuration object
- Persist a task configuration
- Use the task configuration form type
- How to run tasks
- How to scale your application to run tasks concurrently
- How to separate actions in different applications
- Example
- UML
Introduction
Glossary
- An extract_rule refers to a symfony service that will retrieve an array of data. A task will be created for each item of this array.
- An action is a service doing any work you want. It can be triggered by other previous actions in a definable and predictable order (composing what we call a workflow).
- A workflow refers to the way actions are linked together. You can use conditions depending of the results of previous actions to trigger an action or another.
- A task refers to multiple actions linked together for one extracted data. It's a mongo document, and can be used to resume actions if they failed0
- With all these, we can compose a task configuration to define how tasks are created and processed.
Simple schema
Here is a simple schema that will help get a picture of how tasks are created and processed. Each arrow can represent a RabbitMq message that is sent and will be consumed.
Lifecycle of a task with rabbitmq
A task can be created in 2 different ways. The processor service is the entrypoint of this bundle. See the "How to run tasks" part of the documentation for more details.
A single action with some (or no) data to process
- 1 - The task producer send a message with the name of an action and some data (or no data).
- 2 - The task consumer create a single task from these data and use the action producer to send the created task.
- 3 - The action consumer retrieve the task to run the single action.
A complex configuration with a workflow and multiple actions
- 1 - The extract_rule producer send a message to RabbitMQ with the name of the extract rule service.
- 2 - The extract rule consumer extract the data and use the task producer to send a message with the data array.
- 3 - The task consumer create the tasks for each item in the extracted data array, and use the action producer to send the created task.
- 4 - The action consumer read the configuration to run the action depending on the workflow. An action can lead to another one or just end the process.
Installation
Add dependencies in your composer.json
file:
"require": { ..., "idci/task-bundle": "dev-master", }
Enable bundles in your application kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Symfony\Bundle\TwigBundle\TwigBundle(), new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(), new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(), new IDCI\Bundle\TaskBundle\IDCITaskBundle(), ); }
Import the bundle configuration:
# app/config/config.yml imports: - { resource: @IDCITaskBundle/Resources/config/config.yml }
Update your parameters.yml file
application_name: 'Task Runner' task_database_host: localhost task_database_port: ~ task_database_name: task_manager task_database_user: dbuser task_database_password: dbpwd task_rabbitmq_host: localhost task_rabbitmq_port: 5672 task_rabbitmq_user: user task_rabbitmq_password: password task_rabbitmq_lazy: false task_rabbitmq_vhost: / task_mongo_database_name: task task_mongo_database_host: 'mongodb://127.0.0.1:27017'
Run the tests
Install bundle dependencies:
$ make composer-update
To execute unit tests:
$ make phpunit