npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flitter-jobs

v0.4.3

Published

A BullMQ service provider for Flitter.

Downloads

15

Readme

flitter-jobs

Flitter-Jobs is a canonical wrapper for BullMQ that provides:

  • Simple command to start worker nodes
  • Canonical, injectable job classes
  • Queue and worker node configurations
  • Injectable jobs service

Installation

yarn add flitter-jobs

Now, add the Jobs unit to Units.flitter.js (and the Redis unit, if you don't already have that) to the "Pre-Routing Custom Units" section:

'Redis'         : require('./redis/src/RedisUnit'),
'Jobs'          : require('./jobs/src/JobsUnit'),

Deploy & Config

Run the deployments:

./flitter deploy redis      # if you don't have a redis config
./flitter deploy jobs

Be sure to customize the redis.config.js if you need to. Now, you can edit the jobs.config.js to configure job queues, and worker groups.

Job Queues

A job queue can process any different type of job. It's particularly useful as an organizational device, and a means of managing the relative priority of different queues.

Queues can be processed by different (or multiple) workers.

Worker Groups

A worker group is a set of queues that a particular type of worker will process. This can be a single or multiple queues. You can also have multiple worker processes of the same group type, and they will both process all the queues in the worker group.

Basic Usage

Create a new job definition

./flitter new job Test

Add the code to process the job in the execute method of the new Job class that was created in app/jobs/Test.job.js:

const { Job } = require('flitter-jobs')

class TestJob extends Job {
    static get services() {
        return [...super.services, 'output']
    }

    async execute(job) {
        const { data } = job
        this.output.info('Test job executed with data: ')
        this.output.info(data)
    }
}

module.exports = exports = TestJob

The execute method is async, so it returns a promise. The job is considered complete when this promise resolves. The first parameter of this method is an instance of BullMQ's Job Class.

Create a new queue and worker group

In config/jobs.config.js, create a new queue called low_priority, and a worker group called main to process it:

const jobs_config = {
    queues: [ 'low_priority' ],
    workers: {
        main: {
            queues: ['low_priority'],
        },
    },
}

module.exports = exports = jobs_config

Start the Worker

As a separate process, you can start the worker to process the jobs by starting it with the command:

./flitter worker main

Add Jobs to the Queue

Now, from your main application (or the Flitter shell), you can add jobs to the queue and they will be processed by the worker node:

(flitter)> const lp_queue = _services.jobs.queue('low_priority')
(flitter)> lp_queue.add('Test', { some: 'data' })

In this case, we get the low_priority queue instance and add a new Test job. You can add jobs by their canonical name as they were created.

If you look at the output of the worker process, you should see the processing message:

[INFO] [Test] Test job executed with data:
[INFO] [Test] { some: 'data' }

See the BullMQ docs for more usage information.