Atributo

Creates an object which allocates jobs across a number of instances.

new Atributo(options: Object)

Extends EventEmitter

Parameters
options (Object) Configuration options.
Name Description
options.db_type ("sqlite" | "pg") (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 .
Instance Members
close(cb?)
available(instance_id, cb)
unavailable(instance_id, destroyed, cb)
instances(cb)
allocate(job_id, cb)
deallocate(job_id, cb)
has_jobs(instance_id, cb)
jobs(instance_id, cb)
instance(job_id, cb)
_allocate(job_id, instance_ids, cb)
Events
ready
close

closeCallback

Callback type for closing the database file.

closeCallback(err: Error?)

Type: Function

Parameters
err (Error?) Error, if one occurred.

availableCallback

Callback type for making an instance available.

availableCallback(err: Error?)

Type: Function

Parameters
err (Error?) Error, if one occurred.

unavailableCallback

Callback type for making an instance unavailable.

unavailableCallback(err: Error?)

Type: Function

Parameters
err (Error?) Error, if one occurred.

instancesCallback

Callback type for listing instances.

instancesCallback(err: Error?, instances: Object<string, boolean>)

Type: Function

Parameters
err (Error?) Error, if one occurred.
instances (Object<string, boolean>) Map of instance ID to availability.

allocateCallback

Callback type for job allocation.

allocateCallback(err: Error?, instance_id: string, persisted: boolean)

Type: Function

Parameters
err (Error?) Error, if one occurred.
instance_id (string) The ID of the instance to which the job was allocated.
persisted (boolean) Whether the allocation was persisted to the database in this call . If the job was already allocated to an instance in the database, persisted will be false .

deallocateCallback

Callback type for job deallocation.

deallocateCallback(err: Error?)

Type: Function

Parameters
err (Error?) Error, if one occurred.

has_jobsCallback

Callback type for getting whether an instance has jobs allocated to it.

has_jobsCallback(err: Error?, has_jobs: boolean)

Type: Function

Parameters
err (Error?) Error, if one occurred.
has_jobs (boolean) Whether the instance has jobs allocated to it.

jobsCallback

Callback type for getting the jobs allocated to an instance.

jobsCallback(err: Error?, job_ids: Array<string>)

Type: Function

Parameters
err (Error?) Error, if one occurred.
job_ids (Array<string>) The IDs of the jobs allocated to the instance.

instanceCallback

Callback type for getting the instance to which a job is allocated.

instanceCallback(err: Error?, instance_id: string?)

Type: Function

Parameters
err (Error?) Error, if one occurred.
instance_id (string?) The ID of the instance to which the job is allocated, or null if it hasn't been allocated to an instance.

_allocateCallback

Callback type for the job allocator algorithm. This is passed to and called by _allocate. If you override _allocate, make sure you call it.

_allocateCallback(err: Error?, instance_id: string, persist: boolean)

Type: Function

Parameters
err (Error?) Error, if one occurred.
instance_id (string) The instance ID to which the job should be allocated.
persist (boolean) Whether the allocation should be persisted to the database.