sql-queue
TypeScript icon, indicating that this package has built-in type declarations

1.0.1-beta.10 • Public • Published

sql-queue

Execute and track asynchronous functions with sql-queue.

It uses sqlite database to track wether or not function was successfuly executed.


Currently there are 3 states:

  • Failed: -1
  • In progress: 0
  • Finished: 1 (successful)


Usage example
First we need to import and instantiate Queue.

const { Queue } = require('sql-queue')

queue = new Queue('./db.db')

Now we can add a task to queue:
It takes several parameters:

  • execFuntion - function that needs to be executed asynchronously (required)
  • args[] - array of arguments that function takes (optional)
  • info - information about task (optional)
    var taskId = await queue.add(function delayFunction(delayTime){
        return new Promise(r => setTimeout(r, delayTime));
        console.log("task 10 finish")
    }, [10000], "task#10")
    

This is a simple delay function which takes delayTime as argument.
After we execute said code "taskId" will be equal to id assigned
to task in database. It will not wait for function to finish executing but
when when the task is done the database will be updated with appropriate status.


You can also get specific task with id:

    var id = await queue.getById(id)

Get all Tasks:

    var id = await queue.getAll()

Clear all rows in database:

    var id = await queue.clear()

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i sql-queue

Weekly Downloads

1

Version

1.0.1-beta.10

License

ISC

Unpacked Size

19.5 kB

Total Files

13

Last publish

Collaborators

  • nicsxr