Skip to content

Scheduler

endstone.scheduler

Classes relating to letting plugins run code at specific time intervals.

Classes:

Name Description
Scheduler

Represents a scheduler that executes various tasks.

Task

Represents a task being executed by the scheduler.

Scheduler

Represents a scheduler that executes various tasks.

Methods:

Name Description
cancel_task

Removes task from scheduler.

cancel_tasks

Removes all tasks associated with a particular plugin from the scheduler.

get_pending_tasks

Returns a list of all pending tasks.

is_queued

Check if the task is queued to be run later.

is_running

Check if the task is currently running.

run_task

Returns a task that will be executed repeatedly (and synchronously) until cancelled, starting after the

cancel_task

cancel_task(id: int) -> None

Removes task from scheduler.

Parameters:

Name Type Description Default
id int

Id number of task to be removed.

required

cancel_tasks

cancel_tasks(plugin: Plugin) -> None

Removes all tasks associated with a particular plugin from the scheduler.

Parameters:

Name Type Description Default
plugin Plugin

Owner of tasks to be removed.

required

get_pending_tasks

get_pending_tasks() -> list[Task]

Returns a list of all pending tasks.

The ordering of the tasks is NOT related to their order of execution.

is_queued

is_queued(id: int) -> bool

Check if the task is queued to be run later.

Parameters:

Name Type Description Default
id int

The id of the task to check.

required

Returns:

Type Description
bool

True if the task is queued to be run.

is_running

is_running(id: int) -> bool

Check if the task is currently running.

Parameters:

Name Type Description Default
id int

The id of the task to check.

required

Returns:

Type Description
bool

True if the task is currently running.

run_task

run_task(
    plugin: Plugin,
    task: Callable[[], None],
    delay: int = 0,
    period: int = 0,
) -> Task

Returns a task that will be executed repeatedly (and synchronously) until cancelled, starting after the specified number of server ticks.

Parameters:

Name Type Description Default
plugin Plugin

The reference to the plugin scheduling the task.

required
task Callable[[], None]

The task to be run.

required
delay int

The ticks to wait before running the task.

0
period int

The ticks to wait between runs.

0

Returns:

Type Description
Task

A Task that contains the id number (None if task is empty).

Task

Represents a task being executed by the scheduler.

Methods:

Name Description
cancel

Attempts to cancel this task.

Attributes:

Name Type Description
is_cancelled bool

True if this task has been cancelled.

is_sync bool

True if the task is run by the server thread.

owner Plugin

The Plugin that owns this task.

task_id int

The task id number.

is_cancelled property

is_cancelled: bool

True if this task has been cancelled.

is_sync property

is_sync: bool

True if the task is run by the server thread.

owner property

owner: Plugin

The Plugin that owns this task.

task_id property

task_id: int

The task id number.

cancel

cancel() -> None

Attempts to cancel this task.