I've read every available official docs (which is surprisingly not a lot) and all I could get for periodic tasks is this code
.setRecurring(true)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(0, 60))
I know that .setRecurring
makes the job periodic and that the trigger
makes it start in a 60 seconds interval but what about the second time it's executed ? does this mean that the 2nd time would be also executed 60 seconds starting from the 1st one ?
This can't be true because even taking in consideration the optimisation in the background activities and how services run a little later than they're supposed to, programming 60 seconds period while the job runs about 5/10/20 minutes later is too much of a difference. The official docs say that the difference is seconds and maybe a few minutes not over 20 mins.
Basically, my question is does this .setTrigger(Trigger.executionWindow(0, 60))
really mean that the period is 60 seconds or am I gettin this wrong ?
When it is non periodic.
.setRecurring(false)
.setTrigger(Trigger.executionWindow(x, y))
This code will run our job between the time x seconds from the job was scheduled and y seconds from the job was scheduled.
x is know as windowStart, which is the earliest time (in seconds) the job should be considered eligible to run. Calculated from when the job was scheduled (for new jobs)
y is know as windowEnd, The latest time (in seconds) the job should be run in an ideal world. Calculated in the same way as windowStart.
When it is periodic
.setRecurring(true)
.setTrigger(Trigger.executionWindow(x, y))
This code will run our job between the time x seconds from the job was scheduled and y seconds from the job was scheduled.Since this is periodic the next execution will be scheduled x seconds after the job is finished.
May refer this answer also.