Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep For Octane #1040

Merged
merged 1 commit into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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