Skip to content

RedfishGroup/firebase_worker_queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

view on npm

Firebase job queue manager. πŸ”₯πŸ‘©β€πŸš’

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

demo : code, working

Constants

STATUSES

Status constants

available, active, complete, error

Functions

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.

Typedefs

ticketCallback : function
watchQueueAsync : function

Callback used by myFunction.

STATUSES

Status constants

available, active, complete, error

Kind: global constant

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

Kind: global function

Param Type
timestamp firebase.database.ServerValue.TIMESTAMP

TaskException(message, task)

Kind: global function

Param Type
message String
task Task

checkStatus(status)

throws an exception if status is not a legal status

Kind: global function

Param Type
status any

addTask(ref, nTask) β‡’ Promise

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

clearTask(ref, task)

Remove task from queue.

Kind: global function

Param Type
ref FirebaseRef
task Task

changeTaskStatus(ref, task, newStatus, options) β‡’ Promise

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

claimTask(ref, task, workerID) β‡’ Promise.<task>

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

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.

Kind: global function

Param Type
ref FirebaseReference
task Task
result object

errorTask(ref, task, message) β‡’ Promise

Mark a task as having an error.

Kind: global function

Param Type
ref FirebaseRef
task Task
message String

watchQueue(ref, cb, status)

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

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

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

getTask(ref, status) β‡’ Promise

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

taskListener(ref, task, onComplete, onError)

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

taskListenerPromise(ref, task) β‡’ Promise

Alert when a task completes or errors as a promise

Kind: global function

Param Type
ref FirebaseRef
task Task

requeueStaleActiveTasks(ref, [expirationDuration])

Put stale active tasks back on the availabe queue

Kind: global function

Param Type Default
ref Reference
[expirationDuration] number 1000604

monitorForIdle(queueRef, callback, minIdleTime, watchActiveList)

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

ticketCallback : function

Kind: global typedef

Param Type
ticket ticket

watchQueueAsync : function

Callback used by myFunction.

Kind: global typedef

Param Type
ticket Object
Error Object

Β© 2019 Redifish Group LLC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •