Skip to content

Commit

Permalink
prep for octane (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell authored Apr 3, 2021
1 parent 90216ca commit 1316d9b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
23 changes: 22 additions & 1 deletion src/ListensForStorageOpportunities.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Telescope\Contracts\EntriesRepository;

trait ListensForStorageOpportunities
Expand All @@ -25,11 +27,30 @@ trait ListensForStorageOpportunities
*/
public static function listenForStorageOpportunities($app)
{
static::manageRecordingStateForOctane($app);
static::storeEntriesBeforeTermination($app);

static::storeEntriesAfterWorkerLoop($app);
}

/**
* Manage starting and stopping the recording state for Octane.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected static function manageRecordingStateForOctane($app)
{
$app['events']->listen(RequestReceived::class, function ($event) {
if (static::requestIsToApprovedUri($event->request)) {
static::startRecording();
}
});

$app['events']->listen(RequestTerminated::class, function ($event) {
static::stopRecording();
});
}

/**
* Store the entries in queue before the application termination.
*
Expand Down
31 changes: 27 additions & 4 deletions src/Telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,25 @@ public static function start($app)

static::registerMailableTagExtractor();

if (static::runningApprovedArtisanCommand($app) ||
static::handlingApprovedRequest($app)
if (! static::runningWithinOctane($app) &&
(static::runningApprovedArtisanCommand($app) ||
static::handlingApprovedRequest($app))
) {
static::startRecording();
}
}

/**
* Determine if Telescope is running within Octane.
*
* @param \Illuminate\Foundation\Application $app
* @return bool
*/
protected static function runningWithinOctane($app)
{
return isset($_SERVER['LARAVEL_OCTANE']);
}

/**
* Determine if the application is running an approved command.
*
Expand Down Expand Up @@ -190,11 +202,22 @@ protected static function handlingApprovedRequest($app)
return false;
}

return static::requestIsToApprovedUri($app['request']);
}

/**
* Determine if the request is to an approved URI.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected static function requestIsToApprovedUri($request)
{
if (! empty($only = config('telescope.only_paths', []))) {
return $app['request']->is($only);
return $request->is($only);
}

return ! $app['request']->is(
return ! $request->is(
array_merge([
config('telescope.path').'*',
'telescope-api*',
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/EventWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function shouldIgnore($eventName)
protected function eventIsFiredByTheFramework($eventName)
{
return Str::is(
['Illuminate\*', 'eloquent*', 'bootstrapped*', 'bootstrapping*', 'creating*', 'composing*'],
['Illuminate\*', 'Laravel\Octane\*', 'eloquent*', 'bootstrapped*', 'bootstrapping*', 'creating*', 'composing*'],
$eventName
);
}
Expand Down

0 comments on commit 1316d9b

Please sign in to comment.