6
6
use Illuminate \Console \Application as ConsoleApplication ;
7
7
use Illuminate \Console \Scheduling \Event as SchedulingEvent ;
8
8
use Illuminate \Contracts \Cache \Factory as Cache ;
9
- use Illuminate \Contracts \Foundation \Application ;
10
9
use Illuminate \Support \Str ;
11
10
use RuntimeException ;
12
11
use Sentry \CheckIn ;
@@ -23,25 +22,10 @@ class ConsoleSchedulingIntegration extends Feature
23
22
*/
24
23
private $ checkInStore = [];
25
24
26
- /**
27
- * @var Cache The cache repository.
28
- */
29
- private $ cache ;
25
+ private $ shouldHandleCheckIn = false ;
30
26
31
27
public function register (): void
32
28
{
33
- $ this ->onBootInactive ();
34
- }
35
-
36
- public function isApplicable (): bool
37
- {
38
- return $ this ->container ()->make (Application::class)->runningInConsole ();
39
- }
40
-
41
- public function onBoot (Cache $ cache ): void
42
- {
43
- $ this ->cache = $ cache ;
44
-
45
29
$ startCheckIn = function (
46
30
?string $ slug ,
47
31
SchedulingEvent $ scheduled ,
@@ -110,19 +94,19 @@ public function onBoot(Cache $cache): void
110
94
});
111
95
}
112
96
97
+ public function isApplicable (): bool
98
+ {
99
+ return true ;
100
+ }
101
+
102
+ public function onBoot (): void
103
+ {
104
+ $ this ->shouldHandleCheckIn = true ;
105
+ }
106
+
113
107
public function onBootInactive (): void
114
108
{
115
- // This is an exact copy of the macro above, but without doing anything so that even when no DSN is configured the user can still use the macro
116
- SchedulingEvent::macro ('sentryMonitor ' , function (
117
- ?string $ monitorSlug = null ,
118
- ?int $ checkInMargin = null ,
119
- ?int $ maxRuntime = null ,
120
- bool $ updateMonitorConfig = true ,
121
- ?int $ failureIssueThreshold = null ,
122
- ?int $ recoveryThreshold = null
123
- ) {
124
- return $ this ;
125
- });
109
+ $ this ->shouldHandleCheckIn = false ;
126
110
}
127
111
128
112
private function startCheckIn (
@@ -134,6 +118,10 @@ private function startCheckIn(
134
118
?int $ failureIssueThreshold ,
135
119
?int $ recoveryThreshold
136
120
): void {
121
+ if (!$ this ->shouldHandleCheckIn ) {
122
+ return ;
123
+ }
124
+
137
125
$ checkInSlug = $ slug ?? $ this ->makeSlugForScheduled ($ scheduled );
138
126
139
127
$ checkIn = $ this ->createCheckIn ($ checkInSlug , CheckInStatus::inProgress ());
@@ -160,14 +148,18 @@ private function startCheckIn(
160
148
$ this ->checkInStore [$ cacheKey ] = $ checkIn ;
161
149
162
150
if ($ scheduled ->runInBackground ) {
163
- $ this ->cache ->store ()->put ($ cacheKey , $ checkIn ->getId (), $ scheduled ->expiresAt * 60 );
151
+ $ this ->resolveCache () ->store ()->put ($ cacheKey , $ checkIn ->getId (), $ scheduled ->expiresAt * 60 );
164
152
}
165
153
166
154
$ this ->sendCheckIn ($ checkIn );
167
155
}
168
156
169
157
private function finishCheckIn (?string $ slug , SchedulingEvent $ scheduled , CheckInStatus $ status ): void
170
158
{
159
+ if (!$ this ->shouldHandleCheckIn ) {
160
+ return ;
161
+ }
162
+
171
163
$ mutex = $ scheduled ->mutexName ();
172
164
173
165
$ checkInSlug = $ slug ?? $ this ->makeSlugForScheduled ($ scheduled );
@@ -177,7 +169,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI
177
169
$ checkIn = $ this ->checkInStore [$ cacheKey ] ?? null ;
178
170
179
171
if ($ checkIn === null && $ scheduled ->runInBackground ) {
180
- $ checkInId = $ this ->cache ->store ()->get ($ cacheKey );
172
+ $ checkInId = $ this ->resolveCache () ->store ()->get ($ cacheKey );
181
173
182
174
if ($ checkInId !== null ) {
183
175
$ checkIn = $ this ->createCheckIn ($ checkInSlug , $ status , $ checkInId );
@@ -193,7 +185,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI
193
185
unset($ this ->checkInStore [$ mutex ]);
194
186
195
187
if ($ scheduled ->runInBackground ) {
196
- $ this ->cache ->store ()->forget ($ cacheKey );
188
+ $ this ->resolveCache () ->store ()->forget ($ cacheKey );
197
189
}
198
190
199
191
$ checkIn ->setStatus ($ status );
@@ -244,4 +236,9 @@ private function makeSlugForScheduled(SchedulingEvent $scheduled): string
244
236
245
237
return "scheduled_ {$ generatedSlug }" ;
246
238
}
239
+
240
+ private function resolveCache (): Cache
241
+ {
242
+ return $ this ->container ()->make (Cache::class);
243
+ }
247
244
}
0 commit comments