API: scheduler
Source:
job/scheduler.ts
Provides the API for managing scheduled jobs and tasks within the platform, allowing users to retrieve, enable, disable, and trigger jobs, as well as log output.
Usage
import { scheduler } from "sdk/job";
let job = scheduler.getJob("/sample-job/myjob.job");
let param = job.getParameter("myParam");
console.log('Param is: ' + param);Classes
Scheduler
The Scheduler class provides static methods for interacting with the job scheduler,
offering global control over the system's defined jobs.
Methods
getJobs
getJobs ():Job[]Retrieves all job definitions currently configured in the system.
@returns An array of {@link Job} objects.
getJob
getJob (name:string):JobRetrieves a specific job definition by its unique name.
@param name The name of the job.
@returns A {@link Job} object corresponding to the provided name.
enable
enable (name:string):voidEnables a job, allowing it to be executed according to its schedule (cron expression).
@param name The name of the job to enable.
disable
disable (name:string):voidDisables a job, preventing it from executing on its schedule.
@param name The name of the job to disable.
trigger
trigger (name:string, parameters:{[key:string]:string}={}):voidTriggers the immediate execution of a job.
@param name The name of the job to trigger.
@param parameters Optional key-value object of parameters to pass to the job execution.
log
log (name:string, message:string):voidLogs 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.
@param name The name of the job to associate the log with.
@param message The log message content.
error
error (name:string, message:string):voidLogs an error message for a specific job instance.
@param name The name of the job.
@param message The error message content.
warn
warn (name:string, message:string):voidLogs a warning message for a specific job instance.
@param name The name of the job.
@param message The warning message content.
info
info (name:string, message:string):voidLogs an informational message for a specific job instance.
@param name The name of the job.
@param message The information message content.
Job
Represents a single scheduled job definition.
Methods
getName
getName ():stringGets the unique name of the job.
@returns The job name.
getGroup
getGroup ():stringGets the logical grouping for the job.
@returns The job group name.
getClazz
getClazz ():stringGets the Java class name (for Java-based jobs) or script file name (for script-based jobs).
@returns The job implementation class/file name.
getDescription
getDescription ():stringGets the description of the job's purpose.
@returns The job description.
getExpression
getExpression ():stringGets the cron expression defining the job's schedule.
@returns The cron expression string.
getHandler
getHandler ():stringGets the handler file path or resource name for script-based jobs.
@returns The handler path.
getEngine
getEngine ():stringGets the execution engine type (e.g., 'JavaScript', 'Java').
@returns The engine type.
getSingleton
getSingleton ():booleanChecks if the job is configured as a singleton (only one instance runs at a time).
@returns True if the job is a singleton.
getEnabled
getEnabled ():booleanChecks if the job is currently enabled for scheduled execution.
@returns True if the job is enabled.
getCreatedBy
getCreatedBy ():stringGets the user ID who created the job definition.
@returns The creator's user ID.
getCreatedAt
getCreatedAt ():numberGets the timestamp when the job definition was created.
@returns The creation time as a numerical timestamp.
getParameters
getParameters ():JobParametersGets the parameters associated with this job definition.
@returns A {@link JobParameters} object containing all parameters.
getParameter
getParameter (name:string):stringRetrieves the value for a specific parameter of this job.
It checks for an overriding value in the global configurations first,
and falls back to the defined default value if the configuration is not set.
@param name The name of the parameter to retrieve.
@returns The parameter's configured or default value, or null if not found.
enable
enable ():voidEnables this specific job instance.
disable
disable ():voidDisables this specific job instance.
trigger
trigger (parameters:{[key:string]:string}={}):voidTriggers the immediate execution of this job instance.
@param parameters Optional key-value object of parameters to pass to the job execution.
log
log (message:string):voidLogs a message at the standard log level for this job instance.
@param message The log message content.
error
error (message:string):voidLogs an error message for this job instance.
@param message The error message content.
warn
warn (message:string):voidLogs a warning message for this job instance.
@param message The warning message content.
info
info (message:string):voidLogs an informational message for this job instance.
@param message The information message content.
JobParameters
A container object representing the collection of parameters for a {@link Job}.
Methods
get
get (i:number):JobParameterRetrieves a specific job parameter by its index.
@param i The index of the parameter in the array.
@returns A {@link JobParameter} object.
count
count ():numberGets the total number of parameters defined for the job.
@returns The count of parameters.
JobParameter
Represents a single parameter definition for a job.
Methods
getName
getName ():stringGets the name of the parameter.
@returns The parameter name.
getDescription
getDescription ():stringGets the description of the parameter.
@returns The parameter description.
getType
getType ():stringGets the expected data type of the parameter (e.g., 'String', 'Integer', 'Boolean').
@returns The parameter type.
getDefaultValue
getDefaultValue ():stringGets the default value for the parameter.
@returns The default value string.
getChoices
getChoices ():string[]Gets a list of predefined choices for the parameter, if applicable.
@returns An array of choice strings.