Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Introduce a new API to wait until a given scheduled job is completed  #3018

Open
kalaiyarasiganeshalingam opened this issue Jun 20, 2022 · 0 comments
Assignees
Labels
module/task Status/Active Proposals that are under review Team/DIU Data, IO, and Util packages related issues Type/Proposal

Comments

@kalaiyarasiganeshalingam
Copy link
Contributor

kalaiyarasiganeshalingam commented Jun 20, 2022

Summary

In the task module, we can schedule the one-time or recursive job, but this scheduler does not wait until that scheduled job is finished. So we have to on-hold the execution by using runtime:sleep("TIME_IN_SECONDS");. So, this proposal introduces a new API to wait until that scheduled job is completed.

Goals

Provide a way to on-hold the execution until the scheduled task is completed.

Motivation

As mentioned in the summary, the user doesn't have a direct way to on-hold the execution until the scheduled task is completed. If a user scheduled the task with the runtime:sleep API, they have to calculate the time in seconds. So, this way is hard to schedule long-term jobs. It would be easy for them if we provided an API to handle it.

Description

# Schedule the given `task:Job` for the given time and wait until  that task is completed.
# ```ballerina
# time:Utc newTime = time:utcAddSeconds(time:utcNow(), 3);
# time:Civil time = time:utcToCivil(newTime);
# future<Error?> result = task:scheduleOneTimeJobAndWait(new Job(), time);
# ```
#
# + triggerTime - The specific time in Ballerina `time:Civil` to trigger only one time
# + job - Ballerina job, which is to be executed during the trigger
# + return - A `future<Error?>`
public isolated function scheduleOneTimeJobAndWait(Job job, time:Civil triggerTime) returns future<Error?>;
# Schedule the recurring `task:Job` according to the given duration and wait until  that task is completed.
# ```ballerina
# future<Error?> result = task:scheduleJobRecurByFrequency(new Job(), 3);
# ```
#
# + job - Ballerina job, which is to be executed by the scheduler
# + interval - The duration of the trigger (in seconds), which is used to run the job frequently
# + maxCount - The maximum number of trigger counts
# + startTime - The trigger start time in Ballerina `time:Civil`. If it is not provided, a trigger will
#               start immediately
# + endTime - The trigger end time in Ballerina `time:Civil`
# + taskPolicy -  The policy, which is used to handle the error and will be waiting during the trigger time
# + return - A `future<Error?>`
public isolated function scheduleJobRecurByFrequencyAndWait(Job job,  decimal interval,  int maxCount = -1,
                                    time:Civil? startTime = (), time:Civil? endTime = (), 
                                    TaskPolicy taskPolicy = {}) returns future<Error?>;
@kalaiyarasiganeshalingam kalaiyarasiganeshalingam added Type/Proposal module/xmldata Team/DIU Data, IO, and Util packages related issues module/task Status/Active Proposals that are under review and removed module/xmldata labels Jun 20, 2022
@kalaiyarasiganeshalingam kalaiyarasiganeshalingam changed the title Introduce a new API to wait until a given scheduled job is completed Proposal: Introduce a new API to wait until a given scheduled job is completed  Jul 1, 2022
@daneshk daneshk added this to To do in Sprint 59 - Standard Library DIU via automation Jul 1, 2022
@daneshk daneshk removed this from In progress in Sprint 58 - Standard Library DIU Jul 1, 2022
@kaneeldias kaneeldias added this to To do in Sprint 60 - Standard Library DIU via automation Jul 14, 2022
@MadhukaHarith92 MadhukaHarith92 added this to To do in Sprint 61 - Standard Library DIU via automation Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/task Status/Active Proposals that are under review Team/DIU Data, IO, and Util packages related issues Type/Proposal
Projects
None yet
Development

No branches or pull requests

1 participant