Skip to content

Scheduler

Overview

Module

The Scheduler class provides a static façade for managing scheduled jobs and tasks within the platform. It allows users to retrieve job definitions, enable or disable jobs, trigger immediate execution, and log output associated with specific job instances. The Scheduler interacts with the underlying job scheduling system to facilitate the execution of recurring tasks based on cron expressions or other scheduling criteria.

Key Features:

  • Job Retrieval: Methods to retrieve all job definitions or a specific job by name.
  • Job Control: Methods to enable, disable, or trigger jobs on demand.
  • Logging: Methods to log messages at various levels (standard, error, warning, info) for specific job instances.

Use Cases:

  • Task Scheduling: Developers can use the Scheduler to manage tasks that need to run at specific intervals, such as data cleanup, report generation, or any recurring background processing.
  • Monitoring and Debugging: The logging methods allow developers to track the execution of jobs and diagnose issues by associating log messages with specific job instances.

Example Usage:

ts
import { Scheduler } from "@aerokit/sdk/job";

// Retrieve all job definitions
const jobs = Scheduler.getJobs();
console.log(jobs);

// Enable a specific job
Scheduler.enable("myScheduledJob");

// Trigger a job immediately with parameters
Scheduler.trigger("myScheduledJob", { param1: "value1", param2: "value2" });

// Log a message for a specific job instance
Scheduler.log("myScheduledJob", "This is a log message for the job instance.");

Classes

Scheduler

getJobs()

Retrieves all job definitions currently configured in the system.

ts
static getJobs(): void;

Returns

  • Type: void
  • Description: An array of Job objects.

getJob()

Retrieves a specific job definition by its unique name.

ts
static getJob(name: string): Job;
ParameterTypeDescription
namestringThe name of the job.

Returns

  • Type: Job
  • Description: A Job object corresponding to the provided name.

enable()

Enables a job, allowing it to be executed according to its schedule (cron expression).

ts
static enable(name: string): void;
ParameterTypeDescription
namestringThe name of the job to enable.

Returns

  • Type: void
  • Description:

disable()

Disables a job, preventing it from executing on its schedule.

ts
static disable(name: string): void;
ParameterTypeDescription
namestringThe name of the job to disable.

Returns

  • Type: void
  • Description:

trigger()

Triggers the immediate execution of a job.

ts
static trigger(name: string, parameters: any): void;
ParameterTypeDescription
namestringThe name of the job to trigger.
parametersanyOptional key-value object of parameters to pass to the job execution.

Returns

  • Type: void
  • Description:

log()

Logs a message at the standard log level for a specific job instance. This is useful when the log context needs to be associated with a running job.

ts
static log(name: string, message: string): void;
ParameterTypeDescription
namestringThe name of the job to associate the log with.
messagestringThe log message content.

Returns

  • Type: void
  • Description:

error()

Logs an error message for a specific job instance.

ts
static error(name: string, message: string): void;
ParameterTypeDescription
namestringThe name of the job.
messagestringThe error message content.

Returns

  • Type: void
  • Description:

warn()

Logs a warning message for a specific job instance.

ts
static warn(name: string, message: string): void;
ParameterTypeDescription
namestringThe name of the job.
messagestringThe warning message content.

Returns

  • Type: void
  • Description:

info()

Logs an informational message for a specific job instance.

ts
static info(name: string, message: string): void;
ParameterTypeDescription
namestringThe name of the job.
messagestringThe information message content.

Returns

  • Type: void
  • Description: