taskfire

NodeJS Client for Taskfire

Usage no npm install needed!

<script type="module">
  import taskfire from 'https://cdn.skypack.dev/taskfire';
</script>

README

Taskfire Node.js Library

Build Status Coverage Status

Official NodeJS client for Taskfire. The library provides convenient access to the Taskfires API from applications written in server-side JavaScript (Node JS).

Please only use this with server-side Node as it uses your Taskfire project secret token (which should never be publicly revealed).

Install with:

npm install taskfire

Usage

The package needs to be configured with your project's secret token which is available in your project settings. You must instantiate a new client for each project you want to connect to.

Push a job into example-queue-id:

const client = require('taskfire')('<secret_token>')
// OR import taskfire from 'taskfire'
// const client = taskfire(('<secret_token>')

const job = client.queues
  .push('example-queue-id', {
    data: { x: 🤖, y: 2 },
    retries: 3,
  })
  .progress((progress, job) => {
    // Things are moving along! ⏳
  })
  .then((job) => {
    // Work has been completed! 🎉
  })

Create a worker for example-queue-id:

const client = require('taskfire')('<secret_token>')

client.queues
  .process('super-fly-queue', options, async (job, done) => {
    // Work on the queue and report progress
    job.progress(20)

    // Return a promise or call done,
    // when you're finished
    return 👍
  })

API

The API allows either Promise or callbacks to be used.

taskfire (secretAuthToken, options)

Helper function, returns a new instance of TaskfireClient.

TaskfireClient (secretAuthToken, options)

Creates a new instance of the Taskfire client class.

options object properties

Property Default Description
url [wss://api.taskfire.io] The Taskfire API URL.
debug false Add additional console logs

queues.create (queue, cb) => Promise

Creates a new queue.

queue: Object - properties for the new queue

  • [id] - ID of the queue
  • [name] - Name of the queue

[cb]: Function - callback which resolves with Queue

Queue

Queue instances are returned by the client, and represent one queue. They have convenience methods on them to make changes to the queue.

Task

Task instances are returned by the client, and represent one task. They have convenience methods on them to make changes to the task.

Running Tests

Run (at project root): yarn test