new Scheduler(schedule)
Schedule a schedule
Parameters:
| Name | Type | Argument | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
schedule |
Object |
<optional> |
Scheduler.defaults
|
the schedule Properties
|
- Source:
Examples
// ES5
define('bitbucket/plugin/my-plugin', [
'bitbucket/util/scheduler'
], function(
Scheduler
) {
var schedule = new Scheduler({
backoff: {
onBlur: true,
onInactive: true,
},
maxInterval: 10 * Scheduler.MINUTE,
interval: 30 * Scheduler.SECOND,
job: function() {
return getSomeDataFromServer(arg1, arg2);
}
});
schedule.start();
});
// ES2015+
import Schedule, { MINUTE, SECOND } from 'bitbucket/util/scheduler';
const schedule = new Scheduler({
backoff: {
onBlur: true,
onInactive: true,
},
maxInterval: 10 * MINUTE,
interval: 30 * SECOND,
job: () => getSomeDataFromServer(arg1, arg2),
});
schedule.start();
Members
-
<static> defaults :Object
-
Type:
- Object
- Source:
Properties:
Name Type Argument Default Description backoffObject <optional>
the backoff configuration
Properties
Name Type Argument Default Description onBlurboolean <optional>
true should back off on blur?
onInactiveboolean <optional>
true should back off on inactivity?
jitterboolean <optional>
true when enabled a random range is added to the scheduler when it starts
to reduce the likelihood that clients will all reconnect at the same time after an outage.intervalnumber <optional>
10 * SECONDhow often to run the schedule (milliseconds)
immediateTimenumber <optional>
SECONDhow long to wait to run a schedule "immediately".
This is a buffer time taken to wait when starting the schedule (milliseconds).maxIntervalnumber <optional>
5 * MINUTEthe max time the schedule will back off to. (milliseconds)
inactivityTimenumber <optional>
2 * MINUTEthe time at which a user is considered inactive. (milliseconds)
Methods
-
destroy()
-
Stop the scheduler and remove its installed event handlers.
- Source:
-
getBackoffTime() → {number}
-
Get the backoff time based on the last time the user was active and the current level of backoff
- Source:
Returns:
- Type
- number
-
run(immediate, jitterAmount)
-
Run with a given timeout and execute the configured job.
The schedule will be rescheduled once the job's Deferred settles.Parameters:
Name Type Argument Default Description immediateboolean <optional>
false jitterAmountnumber <optional>
0 - Source:
-
start(immediate)
-
Start the scheduler.
Starting a scheduler implies that the user is currently active and optionally immediately starts the run rather
than waiting for the timer to reach its first interval. This immediate run will start after the schedule'simmediateTime.
When starting a scheduler an explicit stop is issued to prevent rogue deferreds/timers from firing.Parameters:
Name Type Argument Description immediateboolean <optional>
- Source:
-
stop()
-
Stop the scheduler. This will abort any in-flight jobs if they are abortable and stop the current run.
- Source:
Type Definitions
-
Schedulerjob() → {Deferred}
-
- Source:
Returns:
- Type
- Deferred