Selaa lähdekoodia

If Iterations value is 0, worker will not kill itself never

* As default, seems logical that default value of iterations if not set is 0
* Also updated documentation
Marc 11 vuotta sitten
vanhempi
commit
216eb24cea
3 muutettua tiedostoa jossa 14 lisäystä ja 3 poistoa
  1. 1 1
      DependencyInjection/Configuration.php
  2. 4 1
      README.md
  3. 9 1
      Service/GearmanExecute.php

+ 1 - 1
DependencyInjection/Configuration.php

@@ -72,7 +72,7 @@ class Configuration implements ConfigurationInterface
                 ->arrayNode('defaults')
                     ->children()
                         ->scalarNode('iterations')
-                            ->defaultValue(150)
+                            ->defaultValue(0)
                         ->end()
                         ->scalarNode('method')
                             ->defaultValue('doNormal')

+ 4 - 1
README.md

@@ -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:
@@ -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

+ 9 - 1
Service/GearmanExecute.php

@@ -149,6 +149,11 @@ class GearmanExecute extends AbstractGearmanService
             $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
          */
@@ -159,7 +164,10 @@ class GearmanExecute extends AbstractGearmanService
                 break;
             }
 
-            if ($iterations-- <= 0) {
+            /**
+             * Only finishes its execution if alive is false and iterations arrives to 0
+             */
+            if (!$alive && $iterations-- <= 0) {
 
                 break;
             }