Skip to content

Commit

Permalink
Merge pull request #61 from InteractionDesignFoundation/laravel-5.7
Browse files Browse the repository at this point in the history
 Fix queue transaction listeners to work with Laravel/Lumen 5.3+
  • Loading branch information
lukewaite authored Feb 6, 2019
2 parents d8d29b8 + 40d63de commit 18673d9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| Laravel Version | Package Tag | Supported |
|-----------------|-------------|-----------|
| 5.4.x | 2.2.x | yes |
| 5.x.x | 2.2.x | yes |
| 5.2.x | 2.1.x | yes |
| 5.1.x | 2.0.x | yes |
| 5.0.x | 2.0.x | no |
Expand Down
33 changes: 14 additions & 19 deletions src/Intouch/LaravelNewrelic/LumenNewrelicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Intouch\LaravelNewrelic;

use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\ServiceProvider;
use Intouch\Newrelic\Newrelic;

Expand All @@ -23,7 +24,7 @@ function ( $app ) {
}
);

app('queue')->before(function (JobProcessed $event) {
app('queue')->before(function (JobProcessing $event) {
app('newrelic')->backgroundJob( true );
app('newrelic')->startTransaction( ini_get('newrelic.appname') );
if (app('config')->get( 'newrelic.auto_name_jobs' )) {
Expand All @@ -41,24 +42,18 @@ function ( $app ) {
*
* @return string
*/
public function getJobName(JobProcessed $event)
public function getJobName(JobProcessing $event)
{
return str_replace(
[
'{connection}',
'{class}',
'{data}',
'{args}',
'{input}',
],
[
$event->connectionName,
get_class($event->job),
json_encode($event->data),
implode(', ', array_keys($event->data)),
implode(', ', array_values($event->data)),
],
$this->app['config']->get( 'newrelic.job_name_provider' )
);
return str_replace(
[
'{connection}',
'{class}',
],
[
$event->connectionName,
$event->job->resolveName(),
],
$this->app['config']->get( 'newrelic.job_name_provider' )
);
}
}
40 changes: 18 additions & 22 deletions src/Intouch/LaravelNewrelic/NewrelicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Intouch\LaravelNewrelic;

use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Routing\Events\RouteMatched;
use Illuminate\Support\ServiceProvider;
use Intouch\Newrelic\Newrelic;
Expand Down Expand Up @@ -92,7 +93,7 @@ protected function registerQueueTransactions()
{
$app = $this->app;

$app['queue']->before(function (JobProcessed $event) use ( $app ) {
$app['queue']->before(function (JobProcessing $event) use ( $app ) {
$app['newrelic']->backgroundJob( true );
$app['newrelic']->startTransaction( ini_get('newrelic.appname') );
if ($app['config']->get( 'newrelic.auto_name_jobs' )) {
Expand All @@ -114,18 +115,18 @@ public function getTransactionName()
{
return str_replace(
[
'{controller}',
'{method}',
'{route}',
'{path}',
'{uri}',
'{controller}',
'{method}',
'{route}',
'{path}',
'{uri}',
],
[
$this->getController(),
$this->getMethod(),
$this->getRoute(),
$this->getPath(),
$this->getUri(),
$this->getController(),
$this->getMethod(),
$this->getRoute(),
$this->getPath(),
$this->getUri(),
],
$this->app['config']->get( 'newrelic.name_provider' )
);
Expand All @@ -134,24 +135,19 @@ public function getTransactionName()
/**
* Build the job name
*
* @param JobProcessing $event
* @return string
*/
public function getJobName(JobProcessed $event)
public function getJobName(JobProcessing $event)
{
return str_replace(
[
'{connection}',
'{class}',
'{data}',
'{args}',
'{input}',
'{connection}',
'{class}',
],
[
$event->connectionName,
get_class($event->job),
json_encode($event->data),
implode(', ', array_keys($event->data)),
implode(', ', array_values($event->data)),
$event->connectionName,
$event->job->resolveName(),
],
$this->app['config']->get( 'newrelic.job_name_provider' )
);
Expand Down
3 changes: 0 additions & 3 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
* a pattern you define yourself, available tokens:
* {connection} = The name of the queue connection
* {class} = The name of the job class
* {data} = JSON string with all data passed to the job
* {args} = List of variable names passed to the job
* {input} = List of values passed to the job
* anything that is not a matched token will remain a string literal
* example:
* Given a job named App\MyJob, with data {"subject":"hello","to":"world"},
Expand Down

0 comments on commit 18673d9

Please sign in to comment.