Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreram committed Sep 5, 2013
2 parents e76980a + 216eb24 commit 71e478a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getConfigTreeBuilder()
->arrayNode('defaults')
->children()
->scalarNode('iterations')
->defaultValue(150)
->defaultValue(0)
->end()
->scalarNode('method')
->defaultValue('doNormal')
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ And register the bundle in your appkernel.php file
## Configuration
We must configure our Worker. Common definitions must be defined in config.yml file, setting values for all installed Workers.
Also we must config gearman cache, using doctrine cache.

> If `iterations` value is 0, worker will not kill itself never, so thread will be alive as long as needed.
> The reason to allow workers to kill themselves is just to prevent each process to accumulate a large quantity of memory.
liip_doctrine_cache:
namespaces:
Expand Down Expand Up @@ -146,7 +149,7 @@ Also we must config gearman cache, using doctrine cache.

# Default number of executions before job dies.
# If annotations defined, will be overwritten
# If empty, 150 is defined by default
# If empty, 0 is defined by default
iterations: 150

# Server list where workers and clients will connect to
Expand Down
10 changes: 9 additions & 1 deletion Service/GearmanExecute.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ private function runJob(\GearmanWorker $gearmanWorker, $objInstance, array $jobs
$gearmanWorker->addFunction($job['realCallableName'], array($objInstance, $job['methodName']));
}

/**
* If iterations value is 0, is like worker will never die
*/
$alive = ( 0 == $iterations );

/**
* Executes GearmanWorker with all jobs defined
*/
Expand All @@ -159,7 +164,10 @@ private function runJob(\GearmanWorker $gearmanWorker, $objInstance, array $jobs
break;
}

if ($iterations-- <= 0) {
/**
* Only finishes its execution if alive is false and iterations arrives to 0
*/
if (!$alive && $iterations-- <= 0) {

break;
}
Expand Down

0 comments on commit 71e478a

Please sign in to comment.