Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hourly recurring Ballerina task executes immediately

Created a task to run in an hour. The first run happens as soon as it is scheduled. Is it the expected behavior?

service /registry on new http:Listener(common:servicePort) {
    function init() returns error? {
        //the job runs for the first time when the service is started, and then it runs periodically
        task:JobId saasApiLoadJobId = check 
                  task:scheduleJobRecurByFrequency(new SaaSAPILoader(0), common:saasApiReloadInterval);
    };

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to provide the start time. The start time of the trigger is in Ballerina time:Civil. If it is not provided, a trigger will start immediately.
Check the API documentation,
https://lib.ballerina.io/ballerina/task/2.5.0#scheduleJobRecurByFrequency

    // start first execution of the task in one hour from now.
    time:Utc startTime = time:utcAddSeconds(time:utcNow(), 3600);
    time:Civil startCivilTime = time:utcToCivil(startTime);
    task:JobId saasApiLoadJobId = check task:scheduleJobRecurByFrequency(new SaaSAPILoader(0), common:saasApiReloadInterva, startTime = startCivilTimel);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading