Ballerina按小时重复任务立即执行是否为预期行为?
关于Ballerina定时任务首次执行的问题
这属于Ballerina task模块的预期行为。
task:scheduleJobRecurByFrequency函数的设计逻辑就是:任务在调度完成后立即执行第一次,之后按照指定的频率周期性运行。你的代码注释也明确提到了"the job runs for the first time when the service is started, and then it runs periodically",这和该函数的实际行为完全匹配。
如果需要让任务首次执行等待指定间隔后再运行,而非立即执行,可以改用task:scheduleJobRecurByFrequencyWithInitialDelay函数,通过设置初始延迟参数来控制首次执行时机。
你的代码片段:
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); }; }
内容的提问来源于stack exchange,提问作者Poorna
相关产品推荐
相关产品推荐

