diff --git a/README.md b/README.md index 7d5665b..d491705 100644 --- a/README.md +++ b/README.md @@ -184,9 +184,13 @@ By default `VERBOSE` environment variable is set when calling php-resque See php-resque logging option : https://github.com/chrisboulton/php-resque#logging +## Use monolog from your kernel + +You can pass a monolog channel to write your logs, see example in supervisor config. Note: Pass Kernel ENV to resque is to instanciate logger, no for sharing kernel between jobs. + ## Running a worker without forking -Sometimes intensive tasks may lose performance with forking mode. We have added a bin/resque-single binary, you can pass kernel file to be loaded only once at start. Be carefull cause if this Worker fails, then you need to restart manually this worker. We recommend to use supervisor to control this, and superlance with memory plugin to restart worker when hits some memory treshold. +Sometimes intensive tasks may lose performance with forking mode. We have added a bin/resque-single binary, you can pass kernel file to be loaded only once at start. Be carefull cause if this Worker fails, then you need to restart manually this worker. We recommend to use supervisor to control this, and superlance with memory plugin to restart worker when hits some memory treshold. Be careful too with your code, shared variables, services instances... etc. ## Adding a delayed job to a queue @@ -258,6 +262,12 @@ user = myusername environment = APP_INCLUDE='/home/sites/myapp/prod/current/vendor/autoload.php',VERBOSE='1',RESQUE_PHP='/home/sites/myapp/prod/current/vendor/chrisboulton/php-resque/lib/Resque.php' stopsignal=QUIT +[program:myapp_phpresque_default_single_worker_logger] +command = /usr/bin/php /home/sites/myapp/prod/current/vendor/instasent/resque-bundle/Instasent/ResqueBundle/bin/resque-single +user = myusername +environment = APP_KERNEL='/home/sites/myapp/prod/current/app/AppKernel.php',LOG_CHANNEL='monolog.logger.custom',APP_INCLUDE='/home/sites/myapp/prod/current/vendor/autoload.php',VERBOSE='1',QUEUE='default' +stopsignal=QUIT + [group:myapp] programs=myapp_phpresque_default,myapp_phpresque_scheduledworker ``` diff --git a/bin/resque b/bin/resque index 5d79e9f..46c3f9f 100755 --- a/bin/resque +++ b/bin/resque @@ -57,6 +57,18 @@ if (!empty($COUNT) && $COUNT > 1) { $count = $COUNT; } +if (getenv('LOG_CHANNEL') && getenv('APP_KERNEL')) { + $file = new SplFileInfo(getenv('APP_KERNEL')); + $class = $file->getBasename('.php'); + + require $file; + + $kernel = new $class(getenv('SYMFONY_ENV'), false); + $kernel->boot(); + + $logger = $kernel->getContainer()->get(getenv('LOG_CHANNEL')); +} + $PREFIX = getenv('PREFIX'); if (!empty($PREFIX)) { $logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX)); diff --git a/bin/resque-single b/bin/resque-single index 4bf471c..a10b4af 100644 --- a/bin/resque-single +++ b/bin/resque-single @@ -70,6 +70,10 @@ if (getenv('APP_KERNEL')) { $KERNEL = $kernel; } +if (getenv('LOG_CHANNEL')) { + $logger = $KERNEL->getContainer()->get(getenv('LOG_CHANNEL')); +} + $PREFIX = getenv('PREFIX'); if (!empty($PREFIX)) { $logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));