JMSJobQueueBundle icon indicating copy to clipboard operation
JMSJobQueueBundle copied to clipboard

Use console events instead of replacing the console application

Open temp opened this issue 10 years ago • 9 comments

As mentioned in #23, with the console events from symfony 2.3 there is no need to replace the console application.

Instead of using --jms-job-id the RunCommand now sets an env variable, "jmsJobId", which is evaluated in the ConsoleListener. The ConsoleListener listens on all three ConsoleEvents, COMMAND, EXCEPTION and TERMINATE. On COMMAND it adds the tick function, which adds statistics to the job, if statistics are enabled. On EXCEPTION it writes exception information to the job. On TERMINATE it writes memory usage information to the job.

Tested it with PHP 5.5 on Mac OS and Windows. Travis builded successful with 5.3, 5.4 and 5.5, see https://travis-ci.org/temp/JMSJobQueueBundle

I also did a few bugfixes, removed duplicates from composer.json, switch to minimum-stability stable, and of course raised the symfony/framework-bundle requirement to 2.3. In my oppinionen, since this is a long term support version, the raised version shouldn't be a problem.

I did NOT commit a new composer.lock, since this would've raised everything to 2.5. But composer install worked fine, I got the correct versions.

temp avatar Jun 26 '14 11:06 temp

+1

Using the bundle in combination with Symfony 2.5.* and was getting the following error:

[RuntimeException]                         
Job 3:   The "--jms-job-id" option does not exist. 

Running the jms-job-queue:run --verbose --env=dev command, now switched to @temp's branch and it's working all right.

evertharmeling avatar Jul 17 '14 11:07 evertharmeling

We can keep this pull request open for people interested in it, but I'm not ready to drop support for older Symfony versions just yet.

schmittjoh avatar Jul 17 '14 11:07 schmittjoh

@evertharmeling The main version works fine, too - you didn't replace the Console Application, as stated in the docs. My PR is not a bugfix for this, only another way to achieve job stats, without replacement of the Console Application.

temp avatar Jul 17 '14 13:07 temp

Ah ok, my bad, missed that part!

evertharmeling avatar Jul 17 '14 13:07 evertharmeling

@schmittjoh any news on this one? Would love to see this merged. This only affects versions < 2.3. And with 2.7 out all non-LTS versions are unsupported anyway...

temp avatar Aug 26 '15 12:08 temp

+1 for removing --jms-job-id option as it breaks commands that don't support that option. Tested on with 2.6.

jurajseffer avatar Oct 01 '15 09:10 jurajseffer

I am interested too in this PR.

@temp just for the record (CC: @schmittjoh), I think composer.lock should not be commited at all. Just look at symfony/symfony, symfony/assetic-bundle and other packages - there is no composer.lock there since it should only be commited in end user's repo, as information about installed packages in root application. Is any reason that composer.lock is present in this repo?

Wirone avatar Jul 27 '16 07:07 Wirone

Rebased against master and fixed a problem with exception handling in the console listener.

temp avatar Sep 07 '16 12:09 temp

@temp I have merged your code with current official master in my fork (solving conflict in composer.json and removing composer.lock which shouldn't be included in vendor repository at all) and everything seems to work fine without hacking bin/console script (PHP 7.1 & Symfony 3.3).

Thanks for great work :thumbsup:

noofaq avatar Jun 30 '17 15:06 noofaq