murph-doc/docs/tasks.md

38 lines
856 B
Markdown
Raw Normal View History

2021-05-30 20:36:00 +02:00
# Tasks
2021-05-31 16:30:46 +02:00
Tasks are scripts executabled from UI. The creation of tasks is based on events.
2021-05-30 20:36:00 +02:00
```
2022-04-19 20:59:45 +02:00
// src/EventSubscriber/MyTaskEventSubscriber.php
namespace App\EventSubscriber;
2021-05-30 20:36:00 +02:00
use App\Core\Event\Task\TaskInitEvent;
use App\Core\Event\Task\TaskRunRequestedEvent;
use App\Core\EventSuscriber\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');
}
}
```
2021-05-31 16:30:46 +02:00
![](/_static/img/tasks/01.png)
![](/_static/img/tasks/02.png)