浏览代码

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 12 年之前
父节点
当前提交
216eb24cea
共有 3 个文件被更改,包括 14 次插入3 次删除
  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')
                 ->arrayNode('defaults')
                     ->children()
                     ->children()
                         ->scalarNode('iterations')
                         ->scalarNode('iterations')
-                            ->defaultValue(150)
+                            ->defaultValue(0)
                         ->end()
                         ->end()
                         ->scalarNode('method')
                         ->scalarNode('method')
                             ->defaultValue('doNormal')
                             ->defaultValue('doNormal')

+ 4 - 1
README.md

@@ -100,6 +100,9 @@ And register the bundle in your appkernel.php file
 ## Configuration
 ## Configuration
 We must configure our Worker. Common definitions must be defined in config.yml file, setting values for all installed Workers. 
 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.
 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:
     liip_doctrine_cache:
         namespaces:
         namespaces:
@@ -146,7 +149,7 @@ Also we must config gearman cache, using doctrine cache.
 
 
             # Default number of executions before job dies.
             # Default number of executions before job dies.
             # If annotations defined, will be overwritten
             # If annotations defined, will be overwritten
-            # If empty, 150 is defined by default
+            # If empty, 0 is defined by default
             iterations: 150
             iterations: 150
 
 
         # Server list where workers and clients will connect to
         # 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']));
             $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
          * Executes GearmanWorker with all jobs defined
          */
          */
@@ -159,7 +164,10 @@ class GearmanExecute extends AbstractGearmanService
                 break;
                 break;
             }
             }
 
 
-            if ($iterations-- <= 0) {
+            /**
+             * Only finishes its execution if alive is false and iterations arrives to 0
+             */
+            if (!$alive && $iterations-- <= 0) {
 
 
                 break;
                 break;
             }
             }