Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

536 lines (367 sloc) 16.746 kb

File: "power-queue.js" Where: {client|server}

new PowerQueue([options])  Anywhere

Creates an instance of a power queue 
[Check out demo](http://power-queue-test.meteor.com/)

Arguments

  • options {object} (Optional) Settings
    • filo {boolean} (Default = false) Make it a first in last out queue
    • isPaused {boolean} (Default = false) Set queue paused
    • autostart {boolean} (Default = true) May adding a task start the queue
    • name {string} (Default = "Queue") Name of the queue
    • maxProcessing {number} (Default = 1) Limit of simultanous running tasks
    • maxFailures {number} (Default = 5) Limit retries of failed tasks, if 0 or below we allow infinite failures
    • jumpOnFailure {number} (Default = true) Jump to next task and retry failed task later
    • debug {boolean} (Default = false) Log verbose messages to the console
    • reactive {boolean} (Default = true) Set whether or not this queue should be reactive
    • spinalQueue {SpinalQueue} (Optional) Set spinal queue uses pr. default MicroQueue or ReactiveList if added to the project

PowerQueue = function(options) { ... power-queue.js:27

powerqueue.onEnded  Anywhere

This callback onEnded is defined in PowerQueue Is called when queue is ended

self.onEnded = options && options.onEnded || function() { ... power-queue.js:103

powerqueue.onRelease  Anywhere

This callback onRelease is defined in PowerQueue Is called when queue is released

self.onRelease = options && options.onRelease || function() { ... power-queue.js:110

powerqueue.onAutostart  Anywhere

This callback onAutostart is defined in PowerQueue Is called when queue is auto started

self.onAutostart = options && options.onAutostart || function() { ... power-queue.js:115

powerqueue.total()  Anywhere

This method total is defined in PowerQueue

Returns {number} (is reactive) The total number of tasks added to this queue

self.total = self._maxLength.get; power-queue.js:123

powerqueue.isPaused()  Anywhere

This method isPaused is defined in PowerQueue

Returns {boolean} (is reactive) Status of the paused state of the queue

self.isPaused = self._paused.get; power-queue.js:129

powerqueue.processing()  Anywhere

This method processing is defined in PowerQueue

Returns {number} (is reactive) Number of tasks currently being processed

self.processing = self._isProcessing.get; power-queue.js:135

powerqueue.errors()  Anywhere

This method errors is defined in PowerQueue

Returns {number} (is reactive) The total number of errors Errors are triggered when maxFailures are exeeded

self.errors = self._errors.get; power-queue.js:142

powerqueue.failures()  Anywhere

This method failures is defined in PowerQueue

Returns {number} (is reactive) The total number of failed tasks

self.failures = self._failures.get; power-queue.js:148

powerqueue.isRunning()  Anywhere

This method isRunning is defined in PowerQueue

Returns {boolean} (is reactive) True if the queue is running

NOTE: The task can be paused but marked as running

self.isRunning = self._running.get; power-queue.js:155

powerqueue.maxProcessing([max])  Anywhere

This method maxProcessing is defined in PowerQueue

Arguments

  • max {number} (Optional) If not used this function works as a getter

Returns {number} (is reactive) Maximum number of simultaneous processing tasks

Example:

  foo.maxProcessing();    // Works as a getter and returns the current value
  foo.maxProcessing(20);  // This sets the value to 20

self.maxProcessing = self._maxProcessing.getset; power-queue.js:168

powerqueue.autostart([autorun])  Anywhere

This method autostart is defined in PowerQueue

Arguments

  • autorun {boolean} (Optional) If not used this function works as a getter

Returns {boolean} (is reactive) If adding a task may trigger the queue to start

Example:

  foo.autostart();    // Works as a getter and returns the current value
  foo.autostart(true);  // This sets the value to true

self.autostart = self._autostart.getset; power-queue.js:189

powerqueue.maxFailures([max])  Anywhere

This method maxFailures is defined in PowerQueue

Arguments

  • max {number} (Optional) If not used this function works as a getter

Returns {number} (is reactive) The maximum for failures pr. task before triggering an error

Example:

  foo.maxFailures();    // Works as a getter and returns the current value
  foo.maxFailures(10);  // This sets the value to 10

self.maxFailures = self._maxFailures.getset; power-queue.js:202

powerqueue.processList()  Anywhere

This method processList is defined in prototype of PowerQueue

Returns {array} (is reactive) List of tasks currently being processed

PowerQueue.prototype.processingList = function() { ... power-queue.js:209

powerqueue.isHalted()  Anywhere

This method isHalted is defined in prototype of PowerQueue

Returns {boolean} (is reactive) True if the queue is not running or paused

PowerQueue.prototype.isHalted = function() { ... power-queue.js:218

powerqueue.length()  Anywhere

This method length is defined in prototype of PowerQueue

Returns {number} (is reactive) Number of tasks left in queue to be processed

PowerQueue.prototype.length = function() { ... power-queue.js:227

powerqueue.progress()  Anywhere

This method progress is defined in prototype of PowerQueue

Returns {number} (is reactive) 0 .. 100 % Indicates the status of the queue

PowerQueue.prototype.progress = function() { ... power-queue.js:236

powerqueue.usage()  Anywhere

This method usage is defined in prototype of PowerQueue

Returns {number} (is reactive) 0 .. 100 % Indicates ressource usage of the queue

PowerQueue.prototype.usage = function() { ... power-queue.js:249

powerqueue.reset()  Anywhere

This method reset is defined in prototype of PowerQueue Calling this will:

  • stop the queue
  • paused to false
  • Discart all queue data

NOTE: At the moment if the queue has processing tasks they can change the errors and failures counters. This could change in the future or be prevented by creating a whole new instance of the PowerQueue

PowerQueue.prototype.reset = function() { ... power-queue.js:264

powerqueue._autoStartTasks()  Anywhere

This method is private This method __autoStartTasks_ is defined in PowerQueue

This method defines the autostart algorithm that allows add task to trigger a start of the queue if queue is not paused.

PowerQueue.prototype._autoStartTasks = function() { ... power-queue.js:289

powerqueue.add(data, [failures])  Anywhere

This method add is defined in prototype of PowerQueue

Arguments

  • data {any}
    The task to be handled
  • failures {number} (Optional) Internally used to Pass on number of failures.

PowerQueue.prototype.add = function(data, failures, id) { ... power-queue.js:316

powerqueue.updateThrottleUp()  Anywhere

This method is private This method updateThrottleUp is defined in prototype of PowerQueue

Calling this method will update the throttle on the queue adding tasks.

Note: Currently we only support the PowerQueue - but we could support a more general interface for pauseable tasks or other usecases.

PowerQueue.prototype.updateThrottleUp = function() { ... power-queue.js:342

powerqueue.updateThrottleDown()  Anywhere

This method is private This method updateThrottleDown is defined in prototype of PowerQueue

Calling this method will update the throttle on the queue pause tasks.

Note: Currently we only support the PowerQueue - but we could support a more general interface for pauseable tasks or other usecases.

PowerQueue.prototype.updateThrottleDown = function() { ... power-queue.js:367

powerqueue.next([err])  Anywhere

This method next is defined in prototype of PowerQueue

Arguments

  • err {string} (Optional) Error message if task failed

  • Can pass in null to start the queue
  • Passing in a string to next will trigger a failure
  • Passing nothing will simply let the next task run next is handed into the taskHandler as a callback to mark an error or end of current task

PowerQueue.prototype.next = function(err) { ... power-queue.js:394

done  Anywhere

Arguments

Explaination of feedback

  • Meteor.Error This means that the task failed in a controlled manner and is allowed to rerun
  • Error This will throw the passed error - as its an unitended error
  • null The task is not done yet, rerun later
  • String The task can perform certain commands on the queue
    • "pause" - pause the queue
    • "stop" - stop the queue
    • "reset" - reset the queue
    • "cancel" - cancel the queue

PowerQueue.prototype.runTaskDone = function(feedback, invocation) { ... power-queue.js:452

powerqueue.runTaskDone([feedback], invocation)  Anywhere

This method is private This method runTaskDone is defined in prototype of PowerQueue

Arguments

Note: feedback is explained in Done callback

PowerQueue.prototype.runTaskDone = function(feedback, invocation) { ... power-queue.js:452

powerqueue.runTask(invocation)  Anywhere

This method is private This method runTask is defined in prototype of PowerQueue

Arguments

  • invocation {object}
    The object stored in the micro-queue

PowerQueue.prototype.runTask = function(invocation) { ... power-queue.js:521

powerqueue.queueTaskHandler()  Anywhere

This method queueTaskHandler is defined in prototype of PowerQueue This method handles tasks that are sub queues

PowerQueue.prototype.queueTaskHandler = function(subQueue, next, failures) { ... power-queue.js:555

powerqueue.taskHandler  Anywhere

This callback taskHandler is defined in prototype of PowerQueue

Arguments

  • data {any}
    This can be data or functions
  • next {function}
    Function next call this to end task
  • failures {number}
    Number of failures on this task

Default task handler expects functions as data:

  self.taskHandler = function(data, next, failures) {
    // This default task handler expects invocation to be a function to run
    if (typeof data !== 'function') {
      throw new Error('Default task handler expects a function');
    }
    try {
      // Have the function call next
      data(next, failures);
    } catch(err) {
      // Throw to fail this task
      next(err);
    }
  };

PowerQueue.prototype.taskHandler = function(data, next, failures) { ... power-queue.js:601

powerqueue.errorHandler  Anywhere

This callback errorHandler is defined in prototype of PowerQueue

Arguments

  • data {any}
    This can be data or functions
  • addTask {function}
    Use this function to insert the data into the queue again
  • failures {number}
    Number of failures on this task

The default callback:

  var foo = new PowerQueue();

  // Overwrite the default action
  foo.errorHandler = function(data, addTask, failures) {
    // This could be overwritten the data contains the task data and addTask
    // is a helper for adding the task to the queue
    // try again: addTask(data);
    // console.log('Terminate at ' + failures + ' failures');
  };

PowerQueue.prototype.errorHandler = function(data, addTask, failures) { ... power-queue.js:634

powerqueue.pause()  Anywhere

This method pause is defined in prototype of PowerQueue

TODO

* We should have it pause all processing tasks

PowerQueue.prototype.pause = function() { ... power-queue.js:645

powerqueue.resume()  Anywhere

This method resume is defined in prototype of PowerQueue

TODO

* We should have it resume all processing tasks

This will not start a stopped queue

PowerQueue.prototype.resume = function() { ... power-queue.js:665

powerqueue.run()  Anywhere

This method run is defined in prototype of PowerQueue

Using this command will resume a paused queue and will start a stopped queue.

PowerQueue.prototype.run = function() { ... power-queue.js:677

Jump to Line
Something went wrong with that request. Please try again.