Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event listener support for Resque's Event/Hook System #84

Open
epicwhale opened this issue Jan 26, 2014 · 8 comments
Open

Event listener support for Resque's Event/Hook System #84

epicwhale opened this issue Jan 26, 2014 · 8 comments

Comments

@epicwhale
Copy link
Contributor

If a job fails due to an exception, I want to log an entry using Monolog. How am I supposed to listen to job failure events with this bundle?

The PHP Resque library supports an Event/Hook System.. what is the recommended approach while using this bundle?

@ruudk
Copy link
Collaborator

ruudk commented Jan 27, 2014

Create a worker_bootstrap.php inside app/ with something like this:

require_once __DIR__ . '/bootstrap.php.cache';
Resque_Event::listen('beforeFork', function(Resque_Job $job) {

});

And then start the worker manually using:

APP_INCLUDE='./app/worker_bootstrap.php' VERBOSE='1' QUEUE='default' php ./vendor/bcc/resque-bundle/BCC/ResqueBundle/bin/resque

@epicwhale
Copy link
Contributor Author

@ruudk How am I suppose to access the Service Container to get access to the logger service within my worker_bootstrap.php? Also, does this make the worker run in the 'prod' environment?

@ruudk
Copy link
Collaborator

ruudk commented Jan 27, 2014

You should prepend ENVIRONMENT='prod' to the line.

There is already support for onFailure (auto retry + logging), see: https://github.com/michelsalib/BCCResqueBundle/blob/master/bin/resque#L67

@epicwhale
Copy link
Contributor Author

@ruudk looks like we need to add ENVIRONMENT='prod' in the README file. Presently its just blank :-S

environment = APP_INCLUDE='/home/sites/myapp/prod/current/vendor...

Why is it just environment =

Checking the onFailure (auto retry + logging)

@epicwhale
Copy link
Contributor Author

Oh, you mean it needs to be

environment = ENVIRONMENT='prod', APP_INCLUDE='/home/sites/myapp/prod/current/vendor/autoload.php',VERBOSE='1',QUEUE='default'

?

@epicwhale
Copy link
Contributor Author

@ruudk I don't see the usage of the ENVIRONMENT variable anywhere in the code base.. :-S Shouldn't it be by default in production environment?

@ruudk
Copy link
Collaborator

ruudk commented Jan 27, 2014

Run the job with

ENVIRONMENT='prod' APP_INCLUDE='./app/worker_bootstrap.php' VERBOSE='1' QUEUE='default' php ./vendor/bcc/resque-bundle/BCC/ResqueBundle/bin/resque

@KeKs0r
Copy link

KeKs0r commented May 14, 2014

I came across the same requirement in order to implement new relic logging. I have to admit, this is not really the most beatiful solution and I think there should be a more integrated way in order to hook into resque events.

In my specific case I would really need the container, since I want to log execution times to new relic. And I would like to access my newRelic handler from the container.

Is there already a new approach to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants