Artwork's avatar

Is Command's Input->IsInteractive supposed to be "true" during a Schedule run?

Dear Developers,

Thank you very much for the ineffably awesome Community and contributions!

Currently, it's Laravel v10.38 in use, and it'll be upgraded eventually at the server I believe.

Meanwhile, I am trying to execute a command which supports confirmations with $this->confirm('...'), but prior the any prompt, I do check the interactivity with $this->input->isInteractive();. It works if executed with PTY/TTY, i.e. in terminal like ./artisan 'some-command';, yet if I do schedule this exact command in Schedule like:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected function commands(): void
    {
        $this->load(__DIR__ . '/Commands');
    }

    protected function schedule(Schedule $schedule): void
    {
        $schedule->command(Commands\SomeCommand::class)->everyMinute();
    }
}

...and then run ./artisan 'schedule:run';, it considers the execution interactive (due to the absence of option no-interaction I presume), and denies any confirmations by default.

Is it expected behavior? Is it expected that $this->input->isInteractive(); returns true during a Schedule run? If so, how would you check whether the command is running inside a schedule and sure consider it non-interactive in such case by default?

Or, is it actually supposed to be scheduled with the option --no-interaction explicitly like?: $schedule->command(Commands\SomeCommand::class, ['--no-interaction'])->everyMinute();.

I would appreciate a suggestion! 🪐

Best and kind regards

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

usually the command might have a --force option to tell the command to proceed without seeking any user input. If you implement this, you can pass --force to the scheduled command?

1 like
Artwork's avatar

@Snapey , thank you for the response!

Yes, I do have such option for the command. The current signature is the following:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class SomeCommand extends Command
{
    protected $signature = 'some-command:example
        {--id= : Specific ID}
        {--user-id= : Specific User ID}
        {--type= : Action type}
        {--y|yes : Confirm prompts by default}
        {--desc : Process actions in descending order}
        {count=20 : Actions count to process}';

// ...

I was curious whether it's actually expected to state --force or --no-interaction explicitly inside Scheduler.

Please or to participate in this conversation.