murph-doc/docs/tasks.md
Simon Vieille 385af624a6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
update theme
2023-02-09 21:50:06 +01:00

872 B

Tasks

Tasks are scripts executabled from UI. The creation of tasks is based on events.

namespace App\EventSubscriber;

use App\Core\Event\Task\TaskInitEvent;
use App\Core\Event\Task\TaskRunRequestedEvent;
use App\Core\EventSubscriber\Task\TaskEventSubscriber;

class MyTaskEventSubscriber extends TaskEventSubscriber
{
    public function onInit(TaskInitEvent $event)
    {
        $event->addTask('my_task', 'Example', 'My task');
    }

    public function onRunRequest(TaskRunRequestedEvent $event)
    {
        if ('my_task' !== $event->getTask()) {
            return;
        }

        $event->getOutput()->writeln('My task is started');

        // ...

        $event->getOutput()->writeln('My task is finished');
    }
}