-
Notifications
You must be signed in to change notification settings - Fork 1
JobSource
JobSource is an ancestor to factories producing Jobs bound to a given Application and all having some common nature, for instance:
Basically, this is a collection of event handers and other options that are set to a job at the moment of creation.
This class is considered abstract parent, so the constructor should be only called through super:
super (app, options)| Name | Description |
|---|---|
app |
an Application instance. |
options |
a bag of options (see below) |
| Name | Type | Default | Description |
|---|---|---|---|
name |
String | The unique name with which this JobSource is registered in the hosting Application | |
globals |
Object | {} |
an object of properties to be injected in each new job as is. For function valued properies, this works like using mixins. |
generators |
Object | {} |
an object of functions to calculate properties (called without any parameters) injected in each new job |
on |
Object | {} |
a bag of event handlers |
rq |
Object | {} |
request parameters, common to all jobs produced |
lag |
Number or Array or Lag | 0 | The minimum time between the constructor call and the finished event |
maxLatency |
Number | Infinity | the maximum time between since the job creation to the end or error event |
maxPending |
Number | Infinity | the maximum number of jobs pending in parallel |
| Name | Type | Description |
|---|---|---|
app |
Application | the constructor's first parameter. |
capacity |
Number | computed as maxPending - pending.size: the number of jobs allowed to be created at once |
lag |
Number or Lag | copy of the lag constructor option |
maxLatency |
Number | copy of the maxLatency constructor option |
maxPending |
Number | copy of the maxPending constructor option |
generators |
Map |
generated from the generators constructor option |
globals |
Map |
generated from the globals constructor option |
pending |
Set |
Jobs created so far, but not yet finished. |
rq |
Object | copy of the rq constructor option |
Adds an event handler to an internal collection.
| Name | Description |
|---|---|
event |
a String, one of Job's event names. |
handler |
a job => {...} function to be set as handler |
If maxPending is exhausted by pending.size, throws a JobSource.OverflowError.
If the numeric value of lag is infinite (which normally means that the Lag instance observed the maximum consecutive errors allowed), throws a JobSource.LockedError.
Otherwise, creates a new Job by the means of this.app, applies all the local options, sets the .src back reference and returns it as a result.
this.rq content is prepended to the rq value.
Emits the reset event. Makes sense to notify lag if it's a Lag instance.
| Name | Description |
|---|---|
JobSource.LockedError |
the class of error thrown when lag is infinite |
JobSource.OverflowError |
the class of error thrown when maxPending is exhausted |
| Name | When emitted | Payload |
|---|---|---|
job-start |
When a new job emits start
|
The job |
job-end |
When a job emits end
|
The job |
job-error |
When a job emits error
|
The job |
job-finish |
When a job emits finish
|
The job |
job-finished |
When a job emits finished
|
The job |
reset |
When reset () is called |