murph-doc/docs/tasks.md

37 lines
872 B
Markdown
Raw Permalink 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
2023-02-09 21:50:06 +01:00
```php-inline title="src/EventSubscriber/MyTaskEventSubscriber.php"
2022-04-19 20:59:45 +02:00
namespace App\EventSubscriber;
2021-05-30 20:36:00 +02:00
use App\Core\Event\Task\TaskInitEvent;
use App\Core\Event\Task\TaskRunRequestedEvent;
2022-04-19 21:00:19 +02:00
use App\Core\EventSubscriber\Task\TaskEventSubscriber;
2021-05-30 20:36:00 +02:00
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)