1.1.1
Creates an object which allocates jobs across a number of instances.
Extends EventEmitter
(Object)
Configuration options.
Name | Description |
---|---|
options.db_type (
(default sqlite )
|
Type of database to use. |
options.db_filename string
|
(sqlite) Filename in which to store the allocations. You can use the same file in multiple
Atributo
objects, even across different processes. They will all make and see the same allocations.
|
options.db_mode integer?
|
(sqlite) Mode to open the file in. See the sqlite3 documentation. |
options.busy_wait integer
(default 1000 )
|
(sqlite) Number of milliseconds to wait before retrying if another
Atributo
object has the database file locked.
|
options.db Object
|
(pg)
node-postgres configuration
.
|
Close the database file. Subsequent operations will fail.
(closeCallback?)
Called once the database is closed.
Make an instance available for job allocation.
(string)
ID of the instance.
(availableCallback)
Called once the instance has been made available.
Make an instance unavailable for job allocation.
(string)
ID of the instance.
(boolean)
If false, the instance won't be allocated any more jobs. If true, it is also removed from the database along with its existing job allocations.
(unavailableCallback)
Called once the instance has been made unavailable.
Get a list of instance IDs along with their availability.
(instancesCallback)
Called with the list of instances.
Allocate a job to an instance.
(string)
ID of the job to allocate.
(allocateCallback)
Called with the ID of the instance to which the job was allocated, and whether the allocation was persisted to the database. The default allocator chooses the instance based on a hash of
job_id
. You can override the
_allocate
function to provide a different allocator.
Remove a job allocation.
(string)
ID of job to deallocate. If the job is allocated to an instance in the database, the allocation will be removed.
(deallocateCallback)
Called when the allocation has been removed.
Get whether an instance has jobs allocated to it.
(string)
ID of the instance.
(has_jobsCallback)
Receives whether there are jobs allocated to to the instance.
Gets the jobs allocated to an instance.
(string)
ID of the instance.
(jobsCallback)
Called with a list of job IDs allocated to the instance.
Gets the instance to which a job is allocated.
(string)
ID of the job.
The default job allocator algorithm. job_id
is hashed, treated as an
integer and used as an index into the array of available instances.
Override this method to provide a different algorithm.
(string)
ID of the job to allocate.
(_allocateCallback)
Your allocator method should call this once it's decided to which instance the job should be allocated.
Callback type for closing the database file.
Type: Function
(Error?)
Error, if one occurred.
Callback type for making an instance available.
Type: Function
(Error?)
Error, if one occurred.
Callback type for making an instance unavailable.
Type: Function
(Error?)
Error, if one occurred.
Callback type for listing instances.
Type: Function
Callback type for job allocation.
Type: Function
Callback type for job deallocation.
Type: Function
(Error?)
Error, if one occurred.
Callback type for getting whether an instance has jobs allocated to it.
Type: Function
Callback type for getting the jobs allocated to an instance.
Type: Function
Callback type for getting the instance to which a job is allocated.
Type: Function
Callback type for the job allocator algorithm.
This is passed to and called by _allocate
.
If you override _allocate
, make sure you call it.
Type: Function