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

[9.x] Command lifecycle handler #44125

Merged
merged 1 commit into from
Sep 15, 2022
Merged

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Sep 14, 2022

This is the command compliment to: #44122

use Carbon\CarbonInterval as Interval;
use Illuminate\Contracts\Console\Kernel;

public function boot()
{
    if (! $this->app->runningInConsole()) {
        return;
    }

    $this->app[Kernel::class]->whenCommandLifecycleIsLongerThan(
        Interval::seconds(1),
        fn ($startedAt, $input, $status) => /* ... */
    );
}

This hook wraps around the Artisan lifecycle, as seen here: https://github.com/laravel/laravel/blob/9.x/artisan#L35-L51

If you were to call the following from a request, it would not trigger this handler.

class MyController
{
    public function __invoke()
    {
        Artisan::call('my-slow-command');
    }
}

I felt that "command lifecycle" made sense, however perhaps it is in fact the "artisan lifecycle".

Request lifecycle and artisan lifecycle? Not sure.

@timacdonald timacdonald force-pushed the command-duration branch 2 times, most recently from 96acab4 to 73dc309 Compare September 15, 2022 01:44
@timacdonald timacdonald marked this pull request as ready for review September 15, 2022 01:49
@timacdonald timacdonald force-pushed the command-duration branch 3 times, most recently from f43eb28 to 0e26f43 Compare September 15, 2022 03:23
@taylorotwell taylorotwell merged commit ba37a05 into laravel:9.x Sep 15, 2022
@timacdonald timacdonald deleted the command-duration branch September 16, 2022 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants