symfony2 gearman worker在清除缓存时停止

时间:2014-06-18 03:52:25

标签: php symfony doctrine-orm backgroundworker gearman

我在symfony(2.4)项目中实施Mmoreram gearman bundle

我有网站,用户可以采取行动并触发工作。

像:

 # Get Gearman and tell it to run in the background a 'job'
        $id = $this->params['gearman']->doHighBackgroundJob('MYBundleServicesPublishWorker~publish',
            json_encode($parameters)
        );

我有一个无限运行并完成工作的工人(迭代:0

我在后台从命令行运行一次:

nohup php /myproject/app/console gearman:worker:execute MYBundleServicesPublishWorker > /tmp/error_log.txt > /tmp/output_log.txt &

配置如下:

gearman:
   # Bundles will parsed searching workers
   bundles:
      # Name of bundle
      MyBundle:

         # Bundle name
         name: myBundle

         # Bundle search can be enabled or disabled
         active: true

         # If any include is defined, Only these namespaces will be parsed
         # Otherwise, full Bundle will be parsed
         include:
            - Services
            - EventListener

         # Namespaces this Bundle will ignore when parsing
         ignore:
            - DependencyInjection
            - Resources

   # default values
   # All these values will be used if are not overwritten in Workers or jobs
   defaults:

      # Default method related with all jobs
      # do // deprecated as of pecl/gearman 1.0.0. Use doNormal
      # doNormal
      # doBackground
      # doHigh
      # doHighBackground
      # doLow
      # doLowBackground
      method: doNormal

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

      # execute callbacks after operations using Kernel events
      callbacks: true

      # Prefix in all jobs
      # If empty name will not be modified
      # Useful for rename jobs in different environments
      job_prefix: null

      # Autogenerate unique key in jobs/tasks if not set
      # This key is unique given a Job name and a payload serialized
      generate_unique_key: true

      # Prepend namespace when callableName is built
      # By default this variable is set as true
      workers_name_prepend_namespace: true

   # Server list where workers and clients will connect to
   # Each server must contain host and port
   # If annotations defined, will be full overwritten
   #
   # If servers empty, simple localhost server is defined by default
   # If port empty, 4730 is defined by efault
   servers:
      localhost:
         host: 127.0.0.1
         port: 4730

doctrine_cache:
    providers:
        gearman_cache:
            type: apc
            namespace: doctrine_cache.ns.gearman

我的问题当我运行app/console cache:clear并且该工作进入工作人员崩溃后

抛出错误:

  

PHP警告:   require_once(/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php):   无法打开流:没有这样的文件或目录   787号线/myproject/app/cache/dev/appDevDebugProjectContainer.php

     

PHP致命错误:require_once():无法打开所需的错误   '/myproject/app/cache/dev/jms_diextra/doctrine/EntityManager_53a06fbf221b4.php'   (include_path ='。:/ usr / share / php:/ usr / share / pear')in   787号线/myproject/app/cache/dev/appDevDebugProjectContainer.php

我如何修复它,我尝试更改doctrine包缓存类型:file_system / array / apc 但它没有帮助

我怎样才能克服这一点? 我做错了什么?

提前致谢

1 个答案:

答案 0 :(得分:0)

我发现了问题,我在工作人员这行:

$this->doctrine->resetEntityManager();

导致这一点,

现在我只是打开连接并关闭它:

$em = $this->doctrine->getEntityManager();
$em->getConnection()->connect();

# run publish command
............
# close connection
$em->getConnection()->close();