Search code examples
typo3schedulertypo3-extensions

TYPO3: Run scheduler task from extbase controller in frontend


The scheduler task is normally executed via the command line script /typo3/sysext/core/bin/typo3 scheduler:run.

Is it possible to call the task inside/with a frontend controller from an extbase extension? (as it is, from the backend module "Scheduler" by clicking "Execute selected tasks")

The goal is to run the task on every pageview of a specific page. (cache disabled)

(No exec/shell_exec available)

Thank you!


Solution

  • The scheduler run script is a Symfony Command Controller. You can run it in your Controller using the following code:

    $schedulerCommand = new \TYPO3\CMS\Scheduler\Command\SchedulerCommand();
    $schedulerInput = new \Symfony\Component\Console\Input\ArrayInput([]);
    $schedulerOutput = new \Symfony\Component\Console\Output\NullOutput();
    $schedulerCommand->run($schedulerInput, $schedulerOutput);
    

    Depending on which tasks you execute, it can take a while to execute and you might run into timeouts.