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 :
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);