29 KiB
Butler
(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
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const result = await plexAPI.butler.getButlerTasks();
// Handle the result
console.log(result)
}
run();
Standalone function
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { butlerGetButlerTasks } from "@lukehagar/plexjs/funcs/butlerGetButlerTasks.js";
// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const res = await butlerGetButlerTasks(plexAPI);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.GetButlerTasksResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models.GetButlerTasksButlerResponseBody | 401 | application/json |
| models.SDKError | 4xx-5xx | / |
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
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const result = await plexAPI.butler.startAllTasks();
// Handle the result
console.log(result)
}
run();
Standalone function
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { butlerStartAllTasks } from "@lukehagar/plexjs/funcs/butlerStartAllTasks.js";
// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const res = await butlerStartAllTasks(plexAPI);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.StartAllTasksResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models.StartAllTasksResponseBody | 401 | application/json |
| models.SDKError | 4xx-5xx | / |
stopAllTasks
This endpoint will stop all currently running tasks and remove any scheduled tasks from the queue.
Example Usage
import { PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const result = await plexAPI.butler.stopAllTasks();
// Handle the result
console.log(result)
}
run();
Standalone function
The standalone function version of this method:
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { butlerStopAllTasks } from "@lukehagar/plexjs/funcs/butlerStopAllTasks.js";
// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const res = await butlerStopAllTasks(plexAPI);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.StopAllTasksResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models.StopAllTasksResponseBody | 401 | application/json |
| models.SDKError | 4xx-5xx | / |
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
import { PlexAPI, TaskName } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const result = await plexAPI.butler.startTask(TaskName.CleanOldBundles);
// Handle the result
console.log(result)
}
run();
Standalone function
The standalone function version of this method:
import { TaskName } from "@lukehagar/plexjs";
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { butlerStartTask } from "@lukehagar/plexjs/funcs/butlerStartTask.js";
// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const res = await butlerStartTask(plexAPI, TaskName.DeepMediaAnalysis);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
taskName |
models.TaskName | ✔️ | the name of the task to be started. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.StartTaskResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models.StartTaskResponseBody | 401 | application/json |
| models.SDKError | 4xx-5xx | / |
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
import { PathParamTaskName, PlexAPI } from "@lukehagar/plexjs";
const plexAPI = new PlexAPI({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const result = await plexAPI.butler.stopTask(PathParamTaskName.BackupDatabase);
// Handle the result
console.log(result)
}
run();
Standalone function
The standalone function version of this method:
import { PathParamTaskName } from "@lukehagar/plexjs";
import { PlexAPICore } from "@lukehagar/plexjs/core.js";
import { butlerStopTask } from "@lukehagar/plexjs/funcs/butlerStopTask.js";
// Use `PlexAPICore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const plexAPI = new PlexAPICore({
accessToken: "<YOUR_API_KEY_HERE>",
xPlexClientIdentifier: "gcgzw5rz2xovp84b4vha3a40",
});
async function run() {
const res = await butlerStopTask(plexAPI, PathParamTaskName.RefreshPeriodicMetadata);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
taskName |
models.PathParamTaskName | ✔️ | The name of the task to be started. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.StopTaskResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| models.StopTaskResponseBody | 401 | application/json |
| models.SDKError | 4xx-5xx | / |