
ballerina/task Ballerina library
Functions
configureWorkerPool
Configure the scheduler worker pool.
check 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[]
Gets all the running jobs.
task:JobId[] result = task:getRunningJobs();
Return Type
- JobId[] - Returns the IDs of all the running jobs as an array
getTimeInMillies
Gets time in milliseconds of the given time:Civil
.
Parameters
- time Civil - The Ballerina
time:Civil
pauseAllJobs
function pauseAllJobs() returns Error?
Pauses all the jobs.
check task:pauseAllJobs();
Return Type
- Error? - A
task:Error
if an error occurred while pausing or else ()
pauseJob
Pauses the particular job.
check 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?
Resumes all the jobs.
check task:resumeAllJobs();
Return Type
- Error? - A
task:Error
when an error occurred while resuming or else ()
resumeJob
Resumes the particular job.
check 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
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.
task: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
scheduleOneTimeJob
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.
time:Utc newTime = time:utcAddSeconds(time:utcNow(), 3); time:Civil time = time:utcToCivil(newTime); task: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
unscheduleJob
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.
check 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 ()
Enums
task: ErrorPolicy
Possible options for the ErrorPolicy
.
Members
task: WaitingPolicy
Possible options for the WaitingPolicy
.
Members
Records
task: JobId
A read-only record consisting of a unique identifier for a created job.
Fields
- id int -
task: TaskPolicy
Policies related to a trigger.
Fields
- errorPolicy ErrorPolicy(default LOG_AND_TERMINATE) - The policy to follow when there is an error in Job execution
- waitingPolicy WaitingPolicy(default WAIT) - The policy to follow when the next task is triggering while the previous job is still being processing
Errors
task: Error
Represents the error type of the ballerina/task
module. This error type represents any error that can occur during
the execution of the task APIs.
Object types
task: Job
The Ballerina Job object provides the abstraction for a job instance, which schedules to execute periodically.
execute
function execute()
Executes by the Scheduler when the scheduled trigger fires.
Import
import ballerina/task;
Metadata
Released date: 5 months ago
Version: 2.6.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0
GraalVM compatible: Yes
Pull count
Total: 177187
Current verison: 16
Weekly downloads
Keywords
task
job
schedule
Contributors
Dependencies