如何使用Job类成功地使用ContainerAwareCommand?

时间:2015-12-28 02:35:46

标签: symfony

这是我的ContainerAwareCommand类,

class myCommand extends ContainerAwareCommand
{
   protected function configure()
   {
      $this
        ->setName('entity:new')
        ->setDescription('my command.')
        ->addArgument(
           'entity',
           InputArgument::REQUIRED,
           'entity ID'
        )
     ;
  }

  protected function execute(InputInterface $input, OutputInterface $output)
  {
     ...
  }
}

以下代码是其他类的功能的一部分,

$job = New Job();
$job->setCommand('entity:new '.$entity->getId());

$this->em->persist($job);
$this->em->flush();

我希望在'$ this-> em-> flush();之后运行myCommand类的执行函数但我觉得这不行。

请告诉我在这种情况下的原因或如何轻松调试我。 我是symfony2初学者。

此致

1 个答案:

答案 0 :(得分:0)

从查看代码开始,我假设您使用JmsJobQueueBundle。您显示的代码仅负责在队列中安排作业。对于要执行的排队作业,您必须手动运行jms-job-queue:run命令或确保is executed in the background

下次请记得提供有关您使用的其他图书馆的更多信息,以便那些没有图书馆的人也可以为您提供帮助。