Skip to content

Commit 18673d9

Browse files
authored
Merge pull request #61 from InteractionDesignFoundation/laravel-5.7
Fix queue transaction listeners to work with Laravel/Lumen 5.3+
2 parents d8d29b8 + 40d63de commit 18673d9

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| Laravel Version | Package Tag | Supported |
44
|-----------------|-------------|-----------|
5-
| 5.4.x | 2.2.x | yes |
5+
| 5.x.x | 2.2.x | yes |
66
| 5.2.x | 2.1.x | yes |
77
| 5.1.x | 2.0.x | yes |
88
| 5.0.x | 2.0.x | no |

src/Intouch/LaravelNewrelic/LumenNewrelicServiceProvider.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Intouch\LaravelNewrelic;
44

55
use Illuminate\Queue\Events\JobProcessed;
6+
use Illuminate\Queue\Events\JobProcessing;
67
use Illuminate\Support\ServiceProvider;
78
use Intouch\Newrelic\Newrelic;
89

@@ -23,7 +24,7 @@ function ( $app ) {
2324
}
2425
);
2526

26-
app('queue')->before(function (JobProcessed $event) {
27+
app('queue')->before(function (JobProcessing $event) {
2728
app('newrelic')->backgroundJob( true );
2829
app('newrelic')->startTransaction( ini_get('newrelic.appname') );
2930
if (app('config')->get( 'newrelic.auto_name_jobs' )) {
@@ -41,24 +42,18 @@ function ( $app ) {
4142
*
4243
* @return string
4344
*/
44-
public function getJobName(JobProcessed $event)
45+
public function getJobName(JobProcessing $event)
4546
{
46-
return str_replace(
47-
[
48-
'{connection}',
49-
'{class}',
50-
'{data}',
51-
'{args}',
52-
'{input}',
53-
],
54-
[
55-
$event->connectionName,
56-
get_class($event->job),
57-
json_encode($event->data),
58-
implode(', ', array_keys($event->data)),
59-
implode(', ', array_values($event->data)),
60-
],
61-
$this->app['config']->get( 'newrelic.job_name_provider' )
62-
);
47+
return str_replace(
48+
[
49+
'{connection}',
50+
'{class}',
51+
],
52+
[
53+
$event->connectionName,
54+
$event->job->resolveName(),
55+
],
56+
$this->app['config']->get( 'newrelic.job_name_provider' )
57+
);
6358
}
6459
}

src/Intouch/LaravelNewrelic/NewrelicServiceProvider.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace Intouch\LaravelNewrelic;
1818

1919
use Illuminate\Queue\Events\JobProcessed;
20+
use Illuminate\Queue\Events\JobProcessing;
2021
use Illuminate\Routing\Events\RouteMatched;
2122
use Illuminate\Support\ServiceProvider;
2223
use Intouch\Newrelic\Newrelic;
@@ -92,7 +93,7 @@ protected function registerQueueTransactions()
9293
{
9394
$app = $this->app;
9495

95-
$app['queue']->before(function (JobProcessed $event) use ( $app ) {
96+
$app['queue']->before(function (JobProcessing $event) use ( $app ) {
9697
$app['newrelic']->backgroundJob( true );
9798
$app['newrelic']->startTransaction( ini_get('newrelic.appname') );
9899
if ($app['config']->get( 'newrelic.auto_name_jobs' )) {
@@ -114,18 +115,18 @@ public function getTransactionName()
114115
{
115116
return str_replace(
116117
[
117-
'{controller}',
118-
'{method}',
119-
'{route}',
120-
'{path}',
121-
'{uri}',
118+
'{controller}',
119+
'{method}',
120+
'{route}',
121+
'{path}',
122+
'{uri}',
122123
],
123124
[
124-
$this->getController(),
125-
$this->getMethod(),
126-
$this->getRoute(),
127-
$this->getPath(),
128-
$this->getUri(),
125+
$this->getController(),
126+
$this->getMethod(),
127+
$this->getRoute(),
128+
$this->getPath(),
129+
$this->getUri(),
129130
],
130131
$this->app['config']->get( 'newrelic.name_provider' )
131132
);
@@ -134,24 +135,19 @@ public function getTransactionName()
134135
/**
135136
* Build the job name
136137
*
138+
* @param JobProcessing $event
137139
* @return string
138140
*/
139-
public function getJobName(JobProcessed $event)
141+
public function getJobName(JobProcessing $event)
140142
{
141143
return str_replace(
142144
[
143-
'{connection}',
144-
'{class}',
145-
'{data}',
146-
'{args}',
147-
'{input}',
145+
'{connection}',
146+
'{class}',
148147
],
149148
[
150-
$event->connectionName,
151-
get_class($event->job),
152-
json_encode($event->data),
153-
implode(', ', array_keys($event->data)),
154-
implode(', ', array_values($event->data)),
149+
$event->connectionName,
150+
$event->job->resolveName(),
155151
],
156152
$this->app['config']->get( 'newrelic.job_name_provider' )
157153
);

src/config/config.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
* a pattern you define yourself, available tokens:
4949
* {connection} = The name of the queue connection
5050
* {class} = The name of the job class
51-
* {data} = JSON string with all data passed to the job
52-
* {args} = List of variable names passed to the job
53-
* {input} = List of values passed to the job
5451
* anything that is not a matched token will remain a string literal
5552
* example:
5653
* Given a job named App\MyJob, with data {"subject":"hello","to":"world"},

0 commit comments

Comments
 (0)