A library to facilitate the management of an in browser distributed and paralell computation environment.
Firebase is used as the compute manager and dipatcher.
Author: Joshua Thorp
- STATUSES
Status constants
available, active, complete, error
- setServerTimestamp(timestamp)
Timestamp will always be firebase.database.ServerValue.TIMESTAMP
We didn't want firebase as a dependency, but need the constant TIMESTAMP. This function should not be needed until firebase changes the constant. Works for firebase 7.1.0
- TaskException(message, task)
- checkStatus(status)
throws an exception if status is not a legal status
- addTask(ref, nTask) β
Promise
Add a task to the Queue for someone else to do.
- clearTask(ref, task)
Remove task from queue.
- changeTaskStatus(ref, task, newStatus, options) β
Promise
Change the Status of a task.
- claimTask(ref, task, workerID) β
Promise.<task>
Claim a task to be worked on.
- completeTask(ref, task, result) β
Promise
Mark a task as complete, and record the result. The result will be placed in the completed task on firebase.
- errorTask(ref, task, message) β
Promise
Mark a task as having an error.
- watchQueue(ref, cb, status)
Fire callback when new jobs apear. You can claim them in the callback.
- watchQueueAsync(ref, cb, [status])
Watch the queue, and only accept one async task at a time. This will wait for the callback to finish before notifying that another task is avaliable. Note: This is currently slow to start with big queues
- getTask(ref, status) β
Promise
Get the most recent task of a certian status type.
- taskListener(ref, task, onComplete, onError)
Alert when a task completes or errors
- taskListenerPromise(ref, task) β
Promise
Alert when a task completes or errors as a promise
- requeueStaleActiveTasks(ref, [expirationDuration])
Put stale active tasks back on the availabe queue
- monitorForIdle(queueRef, callback, minIdleTime, watchActiveList)
Monitor avaliable tasks and call the callback when it's idle.
- ticketCallback :
function
- watchQueueAsync :
function
Callback used by myFunction.
Status constants
available, active, complete, error
Timestamp will always be firebase.database.ServerValue.TIMESTAMP
We didn't want firebase as a dependency, but need the constant TIMESTAMP. This function should not be needed until firebase changes the constant. Works for firebase 7.1.0
Kind: global function
Param | Type |
---|---|
timestamp | firebase.database.ServerValue.TIMESTAMP |
Kind: global function
Param | Type |
---|---|
message | String |
task | Task |
throws an exception if status is not a legal status
Kind: global function
Param | Type |
---|---|
status | any |
Add a task to the Queue for someone else to do.
Kind: global function
Returns: Promise
- resolves if successfull
Param | Type | Description |
---|---|---|
ref | FirebaseReference |
|
nTask | Task |
It looks like this { value: someValue, signed: 'bravo-niner'} // must be signed |
Remove task from queue.
Kind: global function
Param | Type |
---|---|
ref | FirebaseRef |
task | Task |
Change the Status of a task.
Kind: global function
Returns: Promise
- resolves(new Task), rejects(error)
Param | Type |
---|---|
ref | FirebaseReference |
task | Task |
newStatus | STATUSES |
options | object |
Claim a task to be worked on.
Kind: global function
Returns: Promise.<task>
- Rejects(error) if task has already been claimed. Resolves(Task) otherwise
Param | Type |
---|---|
ref | FirebaseReference |
task | Task |
workerID | String |
Mark a task as complete, and record the result. The result will be placed in the completed task on firebase.
Kind: global function
Param | Type |
---|---|
ref | FirebaseReference |
task | Task |
result | object |
Mark a task as having an error.
Kind: global function
Param | Type |
---|---|
ref | FirebaseRef |
task | Task |
message | String |
Fire callback when new jobs apear. You can claim them in the callback.
Kind: global function
Param | Type | Description |
---|---|---|
ref | FirebaseReference |
|
cb | ticketCallback |
will get called when a new task apears. |
status | STATUSES |
Watch the queue, and only accept one async task at a time. This will wait for the callback to finish before notifying that another task is avaliable. Note: This is currently slow to start with big queues
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
ref | FirebaseRef |
||
cb | watchQueueAsync |
gets called with cb(error, ticket). Error is undefined hopefully. | |
[status] | STATUSES |
STATUSES.available |
Get the most recent task of a certian status type.
Kind: global function
Returns: Promise
- resolve with a Task as the argument.
Param | Type |
---|---|
ref | FirebaseReference |
status | STATUSES |
Alert when a task completes or errors
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
ref | FirebaseRef |
||
task | Task |
||
onComplete | function |
|
. Called on completion |
onError | function |
|
. called on error |
Alert when a task completes or errors as a promise
Kind: global function
Param | Type |
---|---|
ref | FirebaseRef |
task | Task |
Put stale active tasks back on the availabe queue
Kind: global function
Param | Type | Default |
---|---|---|
ref | Reference |
|
[expirationDuration] | number |
1000604 |
Monitor avaliable tasks and call the callback when it's idle.
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
queueRef | FirebaseRef |
||
callback | function |
||
minIdleTime | Number |
60000 |
How long to wait for idle queue |
watchActiveList | Boolean |
false |
Call callback when active list is also empty. This is ooff by default |
Kind: global typedef
Param | Type |
---|---|
ticket | ticket |
Callback used by myFunction.
Kind: global typedef
Param | Type |
---|---|
ticket | Object |
Error | Object |
Β© 2019 Redifish Group LLC