# ServerTaskEvent events

> 5 FeatherPanel plugin events on ServerTaskEvent (4 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/server-task/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 1 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `ServerTaskEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ServerTaskEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerTaskEvent::onServerTaskSequenceUpdated(), function ($userUuid, $serverUuid, $scheduleId, $taskId): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:sequence:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'schedule_id' => $scheduleId, 'task_id' => $taskId]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ServerTaskEvent::onServerTaskCreated()`

- Name: `featherpanel:user:server:task:created`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerTaskEvent.php#L28)

Docblock: string server uuid, int schedule id, array task data. (the emitter passes 4 values, see the table)

Same event name as `ServerEvent::onServerTaskCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `schedule_id` | `$scheduleId` | `int` |
| 4 | `task_id` | `$taskId` | not declared |

When it fires (2 sites)

-   [`CreateTaskTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/CreateTaskTool.php#L239)
-   [`TaskController::createTask`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/TaskController.php#L451)[`POST /api/user/servers/{uuidShort}/schedules/{scheduleId}/tasks`](https://featherpanel.com/docs/api/reference/user/server/tasks/#post-user-servers-uuidShort-schedules-scheduleId-tasks)

```php
$event->on(ServerTaskEvent::onServerTaskCreated(), function ($userUuid, $serverUuid, $scheduleId, $taskId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:created ' . json_encode(['schedule_id' => $scheduleId]));
});
```

## `ServerTaskEvent::onServerTaskDeleted()`

- Name: `featherpanel:user:server:task:deleted`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerTaskEvent.php#L44)

Docblock: string server uuid, int schedule id, int task id. (the emitter passes 4 values, see the table)

Same event name as `ServerEvent::onServerTaskDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `schedule_id` | `$scheduleId` | `int` |
| 4 | `task_id` | `$taskId` | `int` |

When it fires (2 sites)

-   [`DeleteTaskTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/DeleteTaskTool.php#L192)
-   [`TaskController::deleteTask`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/TaskController.php#L1014)[`DELETE /api/user/servers/{uuidShort}/schedules/{scheduleId}/tasks/{taskId}`](https://featherpanel.com/docs/api/reference/user/server/tasks/#delete-user-servers-uuidShort-schedules-scheduleId-tasks-taskId)

```php
$event->on(ServerTaskEvent::onServerTaskDeleted(), function ($userUuid, $serverUuid, $scheduleId, $taskId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:deleted ' . json_encode(['schedule_id' => $scheduleId, 'task_id' => $taskId]));
});
```

## `ServerTaskEvent::onServerTaskError()`

- Name: `featherpanel:user:server:task:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerTaskEvent.php#L61)

Docblock: string error message, array context.

```php
$event->on(ServerTaskEvent::onServerTaskError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ServerTaskEvent::onServerTaskSequenceUpdated()`

- Name: `featherpanel:user:server:task:sequence:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerTaskEvent.php#L52)

Docblock: string server uuid, int schedule id, int task id, array new sequence.

Same event name as `ServerEvent::onServerTaskSequenceUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `int`from docblock |
| 3 | `schedule_id` | `$scheduleId` | `int` |
| 4 | `task_id` | `$taskId` | `int` |

When it fires (1 site)

-   [`TaskController::updateTaskSequence`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/TaskController.php#L772)[`PUT /api/user/servers/{uuidShort}/schedules/{scheduleId}/tasks/{taskId}/sequence`](https://featherpanel.com/docs/api/reference/user/server/tasks/#put-user-servers-uuidShort-schedules-scheduleId-tasks-taskId-sequence)

```php
$event->on(ServerTaskEvent::onServerTaskSequenceUpdated(), function ($userUuid, $serverUuid, $scheduleId, $taskId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:sequence:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'schedule_id' => $scheduleId, 'task_id' => $taskId]));
});
```

## `ServerTaskEvent::onServerTaskUpdated()`

- Name: `featherpanel:user:server:task:updated`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerTaskEvent.php#L36)

Docblock: string server uuid, int schedule id, int task id, array updated data.

Same event name as `ServerEvent::onServerTaskUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `int`from docblock |
| 3 | `schedule_id` | `$scheduleId` | `int` |
| 4 | `task_id` | `$taskId` | `int` |

When it fires (2 sites)

-   [`UpdateTaskTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/UpdateTaskTool.php#L270)
-   [`TaskController::updateTask`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/TaskController.php#L640)[`PUT /api/user/servers/{uuidShort}/schedules/{scheduleId}/tasks/{taskId}`](https://featherpanel.com/docs/api/reference/user/server/tasks/#put-user-servers-uuidShort-schedules-scheduleId-tasks-taskId)

```php
$event->on(ServerTaskEvent::onServerTaskUpdated(), function ($userUuid, $serverUuid, $scheduleId, $taskId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:task:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'schedule_id' => $scheduleId, 'task_id' => $taskId]));
});
```
