Nextcloud PHP API (master)

ISignalHandler

Interface that lets a command cooperatively check whether it was interrupted by the user (Ctrl-C/SIGTERM) and abort accordingly.

#[AsCommand(name: 'app:long-running-task')]
class LongRunningTaskCommand {
    public function __invoke(IOutput $output, ISignalHandler $signalHandler): ExitCode {
        try {
            foreach ($this->items() as $item) {
                $signalHandler->abortIfInterrupted();
                $this->process($item);
            }
        } catch (InterruptedException) {
            $output->writeln('Interrupted by user');
            return ExitCode::Failure;
        }

        return ExitCode::Success;
    }
}
Tags
since
35.0.0
Attributes
#[Consumable]
$since: '35.0.0'

Table of Contents

Methods

abortIfInterrupted()  : void
Throw when interrupted by user (Ctrl-C/SIGTERM)

Methods

On this page

Search results