37 lines
872 B
Markdown
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)
|