7.9 KiB
Butler
Overview
Butler is the task manager of the Plex Media Server Ecosystem.
Available Operations
- getButlerTasks - Get Butler tasks
- startAllTasks - Start all Butler tasks
- stopAllTasks - Stop all Butler tasks
- startTask - Start a single Butler task
- stopTask - Stop a single Butler task
getButlerTasks
Returns a list of butler tasks
Example Usage
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->butler->getButlerTasks();
if ($response->twoHundredApplicationJsonObject !== null) {
// handle response
}
} catch (Exception $e) {
// handle exception
}
Response
?\LukeHagar\Plex_API\Models\Operations\GetButlerTasksResponse
startAllTasks
This endpoint will attempt to start all Butler tasks that are enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
- Any tasks not scheduled to run on the current day will be skipped.
- If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
- If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
- If we are outside the configured window, the task will start immediately.
Example Usage
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->butler->startAllTasks();
if ($response->statusCode === 200) {
// handle response
}
} catch (Exception $e) {
// handle exception
}
Response
?\LukeHagar\Plex_API\Models\Operations\StartAllTasksResponse
stopAllTasks
This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
Example Usage
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->butler->stopAllTasks();
if ($response->statusCode === 200) {
// handle response
}
} catch (Exception $e) {
// handle exception
}
Response
?\LukeHagar\Plex_API\Models\Operations\StopAllTasksResponse
startTask
This endpoint will attempt to start a single Butler task that is enabled in the settings. Butler tasks normally run automatically during a time window configured on the server's Settings page but can be manually started using this endpoint. Tasks will run with the following criteria:
- Any tasks not scheduled to run on the current day will be skipped.
- If a task is configured to run at a random time during the configured window and we are outside that window, the task will start immediately.
- If a task is configured to run at a random time during the configured window and we are within that window, the task will be scheduled at a random time within the window.
- If we are outside the configured window, the task will start immediately.
Example Usage
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
use \LukeHagar\Plex_API\Models\Operations;
$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->butler->startTask(Operations\TaskName::CleanOldBundles);
if ($response->statusCode === 200) {
// handle response
}
} catch (Exception $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
taskName |
\LukeHagar\Plex_API\Models\Operations\TaskName | ✔️ | the name of the task to be started. |
Response
?\LukeHagar\Plex_API\Models\Operations\StartTaskResponse
stopTask
This endpoint will stop a currently running task by name, or remove it from the list of scheduled tasks if it exists. See the section above for a list of task names for this endpoint.
Example Usage
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use \LukeHagar\Plex_API;
use \LukeHagar\Plex_API\Models\Components;
use \LukeHagar\Plex_API\Models\Operations;
$security = new Components\Security();
$security->accessToken = '<YOUR_API_KEY_HERE>';
$sdk = Plex_API\PlexAPI::builder()->setSecurity($security)->build();
try {
$response = $sdk->butler->stopTask(Operations\PathParamTaskName::BackupDatabase);
if ($response->statusCode === 200) {
// handle response
}
} catch (Exception $e) {
// handle exception
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
taskName |
\LukeHagar\Plex_API\Models\Operations\PathParamTaskName | ✔️ | The name of the task to be started. |