Skip to content

Commit ed3dd75

Browse files
committed
Optimalization: get events dispatcher once
1 parent 74442a6 commit ed3dd75

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/CloudTasksServiceProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,17 @@ private function registerRoutes(): void
128128

129129
private function registerDashboard(): void
130130
{
131-
app('events')->listen(TaskCreated::class, function (TaskCreated $event) {
131+
$events = $this->app['events'];
132+
133+
$events->listen(TaskCreated::class, function (TaskCreated $event) {
132134
if (CloudTasks::dashboardDisabled()) {
133135
return;
134136
}
135137

136138
DashboardService::make()->add($event->queue, $event->task);
137139
});
138140

139-
app('events')->listen(JobFailed::class, function (JobFailed $event) {
141+
$events->listen(JobFailed::class, function (JobFailed $event) {
140142
if (!$event->job instanceof CloudTasksJob) {
141143
return;
142144
}
@@ -149,7 +151,7 @@ private function registerDashboard(): void
149151
);
150152
});
151153

152-
app('events')->listen(JobProcessing::class, function (JobProcessing $event) {
154+
$events->listen(JobProcessing::class, function (JobProcessing $event) {
153155
if (!$event->job instanceof CloudTasksJob) {
154156
return;
155157
}
@@ -159,7 +161,7 @@ private function registerDashboard(): void
159161
}
160162
});
161163

162-
app('events')->listen(JobProcessed::class, function (JobProcessed $event) {
164+
$events->listen(JobProcessed::class, function (JobProcessed $event) {
163165
if (!$event->job instanceof CloudTasksJob) {
164166
return;
165167
}
@@ -171,7 +173,7 @@ private function registerDashboard(): void
171173
}
172174
});
173175

174-
app('events')->listen(JobExceptionOccurred::class, function (JobExceptionOccurred $event) {
176+
$events->listen(JobExceptionOccurred::class, function (JobExceptionOccurred $event) {
175177
if (!$event->job instanceof CloudTasksJob) {
176178
return;
177179
}
@@ -183,7 +185,7 @@ private function registerDashboard(): void
183185
}
184186
});
185187

186-
app('events')->listen(JobFailed::class, function ($event) {
188+
$events->listen(JobFailed::class, function ($event) {
187189
if (!$event->job instanceof CloudTasksJob) {
188190
return;
189191
}
@@ -193,7 +195,7 @@ private function registerDashboard(): void
193195
}
194196
});
195197

196-
app('events')->listen(JobReleased::class, function (JobReleased $event) {
198+
$events->listen(JobReleased::class, function (JobReleased $event) {
197199
if (!$event->job instanceof CloudTasksJob) {
198200
return;
199201
}

0 commit comments

Comments
 (0)