2012-11-22 183 views
1

我面临着一些问题,在我的听众,同时实施JobQueueEvent,这里是我的我的监听器类Symfony2的JMSJobQueueBundle监听器实现

 
class JobStateChangeListener { 

    function onJobStateChange(StateChangeEvent $event) { 

     if ($event->getJob()->isFinished()) { 
      error_log('Job status is isFinished'); 
     } 

     if ($event->getJob()->isPending()) { 
      error_log('Job status is isPending'); 
     } 

     if ($event->getJob()->isFailed()) { 
      error_log('Job status is isFailed'); 
     } 

     if ($event->getJob()->isRunning()) { 
      error_log('Job status is isRunning'); 
     } 

     if ($event->getJob()->isNew()) { 
      error_log('Job status is isNew'); 
     } 
    } 
} 

这里是我添加的侦听

 
services: 
    jobeventlistener: 
     class: ####\SupportBundle\Listener\JobStateChangeListener 
     tags: 
      - { name: jms_job_queue.job_state_change , method: onJobStateChange } 

这里service.yml是如何JMSjobQueueBundle派遣事件https://github.com/schmittjoh/JMSJobQueueBundle/blob/master/Command/RunCommand.php#L182

更新:ISSUE是当我运行应用程序/控制台jms-job-queue:运行我的监听器,而不是在onJobStateChange func中写入error_log,这可能意味着不在监听。让我知道我做错了什么。

+0

您面临的问题是什么?你没有提到这一点。 –

+0

@ P.R.Ribeiro加了我的问题。 –

回答

2

它因为应用程序/控制台找不到--jms-job-id,您需要更改您的应用程序/控制台文件,只需替换使用Symfony \ Bundle \ FrameworkBundle \ Console \ Application;使用JMS \ JobQueueBundle \ Console \ Application;那么它会正常工作。