Skip to content

Instantly share code, notes, and snippets.

@atayahmet
Last active April 6, 2018 12:03
Show Gist options
  • Save atayahmet/eaa15322e425711be92dc3568c994d11 to your computer and use it in GitHub Desktop.
Save atayahmet/eaa15322e425711be92dc3568c994d11 to your computer and use it in GitHub Desktop.
Queue Service Docs

Queue Service

Queue servis class that we can use in offline projects.

import:

import { queueInstance } from "./app/extensions/Queue";

Workers:

Workers classes should return boolean value in resolve/rejects functions.

Example:

export default class FrameUploaderWorker {
  retry: number = 5;
  
  handle(args: any, queue: Queue): Promise<any> {
    return new Promise((resolve, reject) => {
      resolve(true);
    });
  }
  
  before(args) {
  
  }
  
  after(args) {
  
  }
}

Worker registration: (app/workers.js)

export const workers: any = {
  FrameUploaderWorker
};

API

add()

Parameter: Object

Return: Promise<Boolean>  

Options table:

Name Type Description
name string Short name for worker
worker string Worker full class name that registered
args any The parameters to be used in worker
queueInstance.add({
  "name": "Create entry at remote api",
  "worker": "FrameUploaderWorker",
  "args": {a: 'hello' }
}).then(result => {
  // do something
})

start()

Start queue listener mechanism.

Parameter: None

Return: void

queueInstance.start();

stop()

Stop queue listener mechanism.

Parameter: None

Return: void

queueInstance.stop();

restart()

Restart queue listener mechanism after when current task is done.

Parameter: None

Return: void

queueInstance.restart();

forceRestart()

Force the queue to restart including current task.

Parameter: None

Return: void

queueInstance.forceRestart();

hasTask()

Check tasks in queue listener store.

Parameter: None

Return: Promise<boolean>

Check tasks in queue listener store.

queueInstance.hasTask().then(result => {
  // do something
});

isActive()

Check queue avaibility.

Parameter: None

Return: Boolean

queueInstance.isActive();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment