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

37 lines
872 B
Markdown

# Tasks
Tasks are scripts executabled from UI. The creation of tasks is based on events.
```php-inline title="src/EventSubscriber/MyTaskEventSubscriber.php"
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');
}
}
```
![](/_static/img/tasks/01.png)
![](/_static/img/tasks/02.png)