Skip to content

Commit c1d82ab

Browse files
committed
WIP: Symfony 3&4 Compat
1 parent ded9bd6 commit c1d82ab

File tree

5 files changed

+159
-13
lines changed

5 files changed

+159
-13
lines changed

README.md

Lines changed: 155 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,168 @@
11
# Tasking-Bundle
22

3-
Advanced Tasking Manager for Symfony. 100% Php with Tasks concurrency management.
3+
Advanced Tasking Manager for Symfony. 100% Php with high concurrency management.
44

55
Key features
6-
- 100% PHP, works on any Lunix Server with PHP7 only (TEsted on Jelastic)
7-
- Background tasks concurrency management. Use tokens to prevent tasks being started twice.
8-
- Multi-server Cluster compatible.
9-
- Optimized memory footprint.
6+
- Background tasking: create jobs to be run by workers (Symfony commands)
7+
- 100% PHP, works on any Linux Server with PHP7.2+
8+
- High concurrency management: use jobs token to ensure task is executed by a single process.
9+
- Multi-server compatible: tokens are stored in a central SQL Table.
10+
- Optimized memory footprint: create a dedicated Symfony environnement to reduce memory impacts.
11+
12+
[![Build Status](https://travis-ci.org/SplashSync/Tasking-Bundle.png?branch=master)](https://travis-ci.org/SplashSync/Tasking-Bundle)
13+
[![Total Downloads](https://poser.pugx.org/splash/tasking-bundle/downloads.png)](https://packagist.org/packages/splash/tasking-bundle)
14+
[![Latest Stable Version](https://poser.pugx.org/splash/tasking-bundle/v/stable.png)](https://packagist.org/packages/splash/tasking-bundle)
1015

1116
## Installation
1217

13-
Check out Symfony documentation [here](http://symfony.com/doc/current/bundles/DoctrineBundle/installation.html).
18+
#### Step 1 - Requirements and Installing the bundle
19+
The first step is to tell composer that you want to download Tasking-Bundle which can
20+
be achieved by typing the following at the command prompt:
21+
22+
```bash
23+
composer require splash/tasking-bundle
24+
```
25+
26+
#### Step 2 - Enable the bundle in your kernel
27+
28+
The bundle must be added to your `AppKernel`.
29+
30+
**Step usually not necescary in Symfony 4**.
31+
32+
```php
33+
// app/AppKernel.php
34+
35+
public function registerBundles()
36+
{
37+
return array(
38+
// ...
39+
new Splash\Tasking\SplashTaskingBundle(),
40+
// ...
41+
);
42+
}
43+
```
44+
45+
## Create Your First Job
46+
47+
Background jobs must extend [Splash\Tasking\Model\AbstractJob](https://github.com/SplashSync/Tasking-Bundle/blob/master/src/Model/AbstractJob.php).
48+
49+
```php
50+
use Splash\Tasking\Model\AbstractJob;
51+
52+
class MyJob extends AbstractJob
53+
{
54+
/** @return bool */
55+
public function execute() : bool
56+
{
57+
// Execute your background operations
58+
// ...
59+
return true;
60+
}
61+
}
62+
```
63+
64+
Job Token may be defined multiple way:
65+
66+
```php
67+
use Splash\Tasking\Model\AbstractJob;
68+
69+
class MyJob extends AbstractJob
70+
{
71+
/** You can set it directly by overriding this constant */
72+
protected $token = "";
73+
74+
/**
75+
* Or by writing an array of parameters to setToken()
76+
* @param array $parameters
77+
* @return self
78+
*/
79+
public function setup(array $parameters): self
80+
{
81+
//====================================================================//
82+
// Setup Job Token
83+
$this->setToken($parameters);
84+
85+
return $this;
86+
}
87+
}
88+
```
89+
## Available Job Types
90+
91+
There are few predefined abstract job types, for different kinds of tasks:
92+
- Splash\Tasking\Model\AbstractJob: a single simple task, executed once by job class.
93+
- Splash\Tasking\Model\AbstractServiceJob: execute a Symfony service action with given parameters
94+
- Splash\Tasking\Model\AbstractStaticJob: a simple task, executed & repeated every XX minutes.
95+
- Splash\Tasking\Model\AbstractBatch: step-by-step, execute multiple tasks inside a single job.
96+
97+
## Symfony Commands
98+
99+
The bundle comes with management commands to pilot workers from command line.
100+
```bash
101+
tasking:check Tasking Service : Check Supervisor Process is Running on Current Machines
102+
tasking:start Tasking Service : Start All Supervisors & Workers Process on All Machines
103+
tasking:status Tasking Service : Check Status of Tasking Services
104+
tasking:stop Tasking Service : Stop All Supervisors & Workers Process on All Machines
105+
tasking:supervisor Run a Supervisor Worker Process
106+
tasking:worker Run a Tasking Worker Process
107+
```
108+
109+
**Note: Tasking processes & supervisor are activated & checked each time a new task is added to queue**
110+
111+
## Configuration reference
112+
113+
Bundle configuration are stored under **splash_tasking**:
114+
115+
```yaml
116+
splash_tasking:
117+
entity_manager: default // Name of Doctrine Entity Manager to use for Tasks & Token Storage
118+
environement: prod // Symfony Environnement to use for workers
119+
refresh_delay: 3 // Delay for workers status refresh
120+
watchdog_delay: 30 // Watchdog delay for tasks execution
121+
multiserver: false // Enable multiserver mode
122+
multiserver_path: '' // Url for remote servers checks
123+
server:
124+
force_crontab: false // Use crontab to ensure supervisor is running (Useless if you uses 3+ workers)
125+
php_version: php // Bash comamnd for php
126+
supervisor:
127+
max_age: 3600 // Time to live of supervisor process, if reached, process will die
128+
refresh_delay: 500 // Delay between two worker refresh
129+
max_workers: 3 // Number of worker to use
130+
max_memory: 100 // Max. Memory, if reached, process will die
131+
workers:
132+
max_tasks: 100 // Max. number of jobs to execute, if reached, process will die
133+
max_age: 120 // Time to live of a worker process, if reached, process will die
134+
max_memory: 200 // Max. Memory, if reached, process will die
135+
tasks:
136+
max_age: 180 // Time to live of a finished task in database
137+
try_count: 5 // Number of failed attemps for a task
138+
try_delay: 120 // Delay before retry of a failed task
139+
error_delay: 40 // Delay to consider a started task as failed
140+
static: // Key => Class values for Static Jobs
141+
myStaticJob: AppBundle\Jobs\MyStaticJob
142+
```
143+
144+
## Docker Dev Environnement
145+
146+
A Docker Compose file is available to run a development server.
147+
You can start it typing the following at the command prompt:
148+
149+
```bash
150+
docker-compose up -d
151+
```
152+
153+
## Testing & Code Quality
14154

15-
## Documentation
155+
This bundle uses Phpunit for functional testing.
156+
```bash
157+
docker-compose exec app php vendor/bin/phpunit
158+
```
16159

17-
Check out the documentation [here](https://github.com/SplashSync/Tasking-Bundle/tree/master/Resources/docs).
160+
This bundle uses Grumphp for all code quality checks (PHPMD, PhpCsFixer, PhpStan, and more...).
161+
```bash
162+
docker-compose exec app php vendor/bin/grumphp run
163+
```
18164

19165
## License
20166

21-
This package is available under the [MIT license](LICENSE).
167+
This package is available under the MIT license.
22168

app/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ services:
5050
public: false
5151

5252

53-
Tasking.Sampling.Service:
53+
tasking.sampling.service:
5454
class: Splash\Tasking\Tests\Services\TasksSamplingService
5555
public: true

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#
2222
# This Docker File intend to Create a Complete Dev Environnement
2323
#
24-
# To us different Versions coinfigured, you need to add hosts to /etc/hosts
24+
# To us different Versions configured, you need to add hosts to /etc/hosts
2525
#
2626
# 172.201.0.10 dev.tasking.local
2727
# 172.201.0.200 phpmyadmin.tasking.local

tests/Jobs/TestServiceJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestServiceJob extends AbstractServiceJob
2828
* @var array
2929
*/
3030
protected $inputs = array(
31-
"Service" => "Tasking.Sampling.Service",
31+
"Service" => "tasking.sampling.service",
3232
"Method" => "delayTask",
3333
"Inputs" => array("Delay" => 1),
3434
);

tests/Jobs/TestStaticJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TestStaticJob extends AbstractStaticJob
4242
protected $inputs = array("delay" => 1);
4343

4444
/**
45-
* Job Token is Used for concurency Management
45+
* Job Token is Used for concurrency Management
4646
* You can set it directly by overriding this constant
4747
* or by writing an array of parameters to setJobToken()
4848
*

0 commit comments

Comments
 (0)