final class task_support

internal  
 

Utility wrapper for Moodle's Task API (scheduled and adhoc tasks).

This class provides a stable API for interacting with Moodle tasks, converting core entities into framework-specific DTOs.

Converts all Moodle entities to DTOs and provides a stable, dependency-safe API for the framework.

Methods

scheduled_task_dto|null
get_scheduled_task(string $classname)

Retrieves a specific scheduled task by its class name.

array
get_scheduled_tasks()

Retrieves all scheduled tasks defined in the system.

array
get_adhoc_tasks(string $classname, bool $failedOnly = false)

Retrieves pending adhoc tasks for a specific task class.

bool
queue_adhoc(adhoc_task $task, bool $checkExisting = false)

Queues a new adhoc task for execution.

void
reschedule_or_queue(adhoc_task $task)

Reschedules an existing adhoc task or queues it if not present.

scheduled_task_dto|null
next_scheduled(int $timestamp)

Retrieves the next scheduled task due for execution.

adhoc_task_dto|null
next_adhoc(int $timestamp, bool|null $checkLimits = true, string|null $classname = null)

Retrieves the next adhoc task due for execution.

bool
run_scheduled_from_cli(scheduled_task $task)

Runs a scheduled task from the command line interface.

void
run_adhoc_from_cli(int $taskid)

Runs an adhoc task from the command line interface by its ID.

array
get_adhoc_summary()

Retrieves a summary of all pending adhoc tasks.

array
get_running_tasks(string $sort = '')

Retrieves a list of currently running tasks.

Details

at line 52
scheduled_task_dto|null get_scheduled_task(string $classname)

Retrieves a specific scheduled task by its class name.

Parameters

string $classname

the task class name

Return Value

scheduled_task_dto|null

the task DTO or null if not found

at line 64
array get_scheduled_tasks()

Retrieves all scheduled tasks defined in the system.

Return Value

array

list of scheduled task DTOs

at line 86
array get_adhoc_tasks(string $classname, bool $failedOnly = false)

Retrieves pending adhoc tasks for a specific task class.

Parameters

string $classname

the task class name

bool $failedOnly

whether to only retrieve failed tasks

Return Value

array

list of adhoc task DTOs

at line 104
bool queue_adhoc(adhoc_task $task, bool $checkExisting = false)

Queues a new adhoc task for execution.

Parameters

adhoc_task $task

the adhoc task instance

bool $checkExisting

whether to avoid queuing if an identical task exists

Return Value

bool

True if queued successfully

at line 114
void reschedule_or_queue(adhoc_task $task)

Reschedules an existing adhoc task or queues it if not present.

Parameters

adhoc_task $task

the adhoc task instance

Return Value

void

at line 130
scheduled_task_dto|null next_scheduled(int $timestamp)

Retrieves the next scheduled task due for execution.

Parameters

int $timestamp

the reference timestamp

Return Value

scheduled_task_dto|null

the next task DTO or null

at line 146
adhoc_task_dto|null next_adhoc(int $timestamp, bool|null $checkLimits = true, string|null $classname = null)

Retrieves the next adhoc task due for execution.

Parameters

int $timestamp

the reference timestamp

bool|null $checkLimits

whether to check concurrency limits

string|null $classname

optional task class filter

Return Value

adhoc_task_dto|null

the next task DTO or null

at line 164
bool run_scheduled_from_cli(scheduled_task $task)

Runs a scheduled task from the command line interface.

Parameters

scheduled_task $task

the task instance

Return Value

bool

True on success

at line 174
void run_adhoc_from_cli(int $taskid)

Runs an adhoc task from the command line interface by its ID.

Parameters

int $taskid

the task record ID

Return Value

void

at line 188
array get_adhoc_summary()

Retrieves a summary of all pending adhoc tasks.

Return Value

array

list of task summary DTOs

at line 219
array get_running_tasks(string $sort = '')

Retrieves a list of currently running tasks.

Parameters

string $sort

SQL sort order

Return Value

array

list of running task DTOs