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 backoff
Object <optional>
the backoff configuration
Properties
Name Type Argument Default Description onBlur
boolean <optional>
true should back off on blur?
onInactive
boolean <optional>
true should back off on inactivity?
jitter
boolean <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.interval
number <optional>
10 * SECOND
how often to run the schedule (milliseconds)
immediateTime
number <optional>
SECOND
how long to wait to run a schedule "immediately".
This is a buffer time taken to wait when starting the schedule (milliseconds).maxInterval
number <optional>
5 * MINUTE
the max time the schedule will back off to. (milliseconds)
inactivityTime
number <optional>
2 * MINUTE
the 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 immediate
boolean <optional>
false jitterAmount
number <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 immediate
boolean <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