I am facing some issue in my listener while implementing JobQueueEvent, here is my my listener class
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');
}
}
}
And here is my service.yml for adding listener
services:
jobeventlistener:
class: ####\SupportBundle\Listener\JobStateChangeListener
tags:
- { name: jms_job_queue.job_state_change , method: onJobStateChange }
here is how JMSjobQueueBundle dispatch Event https://github.com/schmittjoh/JMSJobQueueBundle/blob/master/Command/RunCommand.php#L182
Updated: ISSUE is when i run app/console jms-job-queue:run my listener not error_log written in onJobStateChange func, it may means is not listening . let me know what i am doing wrong.
Its Because app/console not find –jms-job-id, you need to change your app/console file just replace use Symfony\Bundle\FrameworkBundle\Console\Application; to use JMS\JobQueueBundle\Console\Application; then it will works fine.