Functions

configureWorkerPool
I

Configure the scheduler worker pool.

getRunningJobs
I

Gets all the running jobs.

getTimeInMillies
I

Gets time in milliseconds of the given time:Civil.

pauseAllJobs
I

Pauses all the jobs.

pauseJob
I

Pauses the particular job.

resumeAllJobs
I

Resumes all the jobs.

resumeJob
I

Resumes the particular job.

scheduleJobRecurByFrequency
I

Schedule the recurring task:Job according to the given duration.

scheduleOneTimeJob
I

Schedule the given task:Job for the given time.

unscheduleJob
I

Unschedule the task:Job, which is associated with the given job ID.

configureWorkerPool

function configureWorkerPool(int workerCount, Seconds waitingTime) returns Error?
Isolated Function

Configure the scheduler worker pool.

1check task:configureWorkerPool(4, 7);

Parameters

  • workerCount int (default 5)
  • Specifies the number of workers that are available for the concurrent execution of jobs. It should be a positive integer. The recommendation is to set a value less than 10. Default sets to 5.

  • waitingTime Seconds (default 5)
  • The number of seconds as a decimal the scheduler will tolerate a trigger to pass its next-fire-time before being considered as ignored the trigger.

Return Type

(Error?)

A task:Error if the process failed due to any reason or else ()

getRunningJobs

function getRunningJobs() returns JobId[ ]
Isolated Function

Gets all the running jobs.

1task:JobId[] result = task:getRunningJobs();

Return Type

(JobId[ ])

Returns the IDs of all the running jobs as an array

getTimeInMillies

function getTimeInMillies(Civil time) returns int | Error
Isolated Function

Gets time in milliseconds of the given time:Civil.

Parameters

  • time Civil
  • The Ballerina time:Civil

Return Type

(int | Error)

Time in milliseconds or else task:Error if the process failed due to any reason

pauseAllJobs

function pauseAllJobs() returns Error?
Isolated Function

Pauses all the jobs.

1check task:pauseAllJobs();

Return Type

(Error?)

A task:Error if an error occurred while pausing or else ()

pauseJob

function pauseJob(JobId jobId) returns Error?
Isolated Function

Pauses the particular job.

1check task:pauseJob(jobId);

Parameters

  • jobId JobId
  • The ID of the job as a task:JobId, which needs to be paused

Return Type

(Error?)

A task:Error if an error occurred while pausing a job or else ()

resumeAllJobs

function resumeAllJobs() returns Error?
Isolated Function

Resumes all the jobs.

1check task:resumeAllJobs();

Return Type

(Error?)

A task:Error when an error occurred while resuming or else ()

resumeJob

function resumeJob(JobId jobId) returns Error?
Isolated Function

Resumes the particular job.

1check task:resumeJob(jobId);

Parameters

  • jobId JobId
  • The ID of the job as a task:JobId, which needs to be resumed

Return Type

(Error?)

A task:Error when an error occurred while resuming a job or else ()

scheduleJobRecurByFrequency

function scheduleJobRecurByFrequency(Job job, decimal interval, int maxCount, Civil? startTime, Civil? endTime, TaskPolicy taskPolicy) returns JobId | Error
Isolated Function

Schedule the recurring task:Job according to the given duration. Once scheduled, it will return the job ID, which can be used to manage the job.

1task:JobId jobId = check task:scheduleJobRecurByFrequency(new Job(), 3);

Parameters

  • job Job
  • Ballerina job, which is to be executed by the scheduler.

  • interval decimal
  • The duration of the trigger (in seconds), which is used to run the job frequently

  • maxCount int (default -1)
  • The maximum number of trigger counts

  • startTime Civil? (default ())
  • The trigger start time in Ballerina time:Civil. If it is not provided, a trigger will start immediately

  • endTime Civil? (default ())
  • The trigger end time in Ballerina time:Civil

  • taskPolicy TaskPolicy (default {})
  • The policy, which is used to handle the error and will be waiting during the trigger time

Return Type

(JobId | Error)

A task:JobId or else a task:Error if the process failed due to any reason

scheduleOneTimeJob

function scheduleOneTimeJob(Job job, Civil triggerTime) returns JobId | Error
Isolated Function

Schedule the given task:Job for the given time. Once scheduled, it will return a job ID, which can be used to manage the job.

1time:Utc newTime = time:utcAddSeconds(time:utcNow(), 3);
2time:Civil time = time:utcToCivil(newTime);
3task:JobId jobId = check task:scheduleOneTimeJob(new Job(), time);

Parameters

  • job Job
  • Ballerina job, which is to be executed during the trigger.

  • triggerTime Civil
  • The specific time in Ballerina time:Civil to trigger only one time

Return Type

(JobId | Error)

A task:JobId or else a task:Error if the process failed due to any reason

unscheduleJob

function unscheduleJob(JobId jobId) returns Error?
Isolated Function

Unschedule the task:Job, which is associated with the given job ID. If no job is running in the scheduler, the scheduler will be shut down automatically.

1check task:unscheduleJob(jobId);

Parameters

  • jobId JobId
  • The ID of the job as a task:JobId, which needs to be unscheduled

Return Type

(Error?)

A task:Error if the process failed due to any reason or else ()