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

@autotelic/fastify-bee-queue

v0.1.0

Published

Fastify plugin for Bee-queue Integration

Downloads

9

Readme

fastify-bee-queue

A plugin for implementing Bee Queue job/task queues in fastify applications.

Install

npm i @autotelic/fastify-bee-queue

Usage

// Server.js
const Fastify = require('fastify')
const { fastifyBeeQueue } = require('@autotelic/fastify-bee-queue')
const fastify = Fastify()

const QUEUE_NAME = 'some-queue-name'

fastify.register(fastifyBeeQueue, {
  redis: 'redis://127.0.0.1',
})

fastify.register(async (fastify, opts) => {
  // Create a Queue instance. By default each Queue will create a connection
  // to redis.
  await fastify.bq.createProducer(QUEUE_NAME)
})

fastify.post('/queue', async (request, response) => {
  const { queues } = fastify.bq
  // Access the Queue Instance
  const q = queues[QUEUE_NAME]
  const { body } = request
  const { x, y } = body
  // Create and save a Job in the Queue.
  q.createJob({ x: parseInt(x), y: parseInt(y) }).save()
  response.send('Scheduled Job')
})

fastify.listen(3000)

// worker.js

// The workerBees function provides a convenience wrapper for creating
// and configuring Queue instances which will process jobs.
const { workerBees } = require('@autotelic/fastify-bee-queue')
const QUEUE_NAME = 'some-queue-name'

// The worker Queue instances to be created.
const workers = [
  {
    name: QUEUE_NAME,
    processor: async (job) => job.data.x + job.data.y,
    options: {}
  }
]

// Base configuration applied to all worker Queues.
const queueOptions = {
  redis: 'redis://127.0.0.1',
}

const { start } = workerBees({ workers, queueOptions })

// Start the workers and begin processing jobs. Start also returns a promise
// which resolves to an array of the running worker Queues.
const queues = await start()

Examples

We provide the following usage examples and recipes:

API

Plugin

Options

  • namespace: The namespace that the plugin decorators will be added to. Defaults to bq

All remaining options will be passed to the Queue instances when they are created. For more details please refer to the Bee Queue settings documentation

Decorators

The plugin exposes the following as decorators under the configured namespace. By default this namespace is bq

createProducer: (name: string, opts: Object)

creates a "Producer" Queue instance. producer Queues are unable to process jobs or receive messages. They are primarily used to add jobs to a Queue.

name: The name of the Queue instance. This is also the lookup key in the queues object.

opts: The Queue instance settings.

create: (name: string, opts: Object)

Creates a worker Queue instance. This queue can process jobs and send/receive messages.

name: The name of the Queue instance. This is also the lookup key in the queues object.

opts: The Queue instance settings.

queues: Object

The key/value store where all created Queue instances are stored. They may be accessed by queue name. The plugin will throw an error if duplicate keys are added to the queues object.

Workers

Utilities for creating bee-queue workers.

workerBees: (configuration: Object) => Object<{ start: () => Promise<Array[Queues]> }>

Creates and starts bee-queue workers for processing jobs.

  • configuration The configuration object for worker bees, expects fields:
    • queueOptions: The Queue settings) which will be applied to all worker Queues.
    • workers: Object - A worker configuration Object which contains fields:
      • name: string - The Name of the queue
      • processor: () => Promise<Any> - An async method to process jobs from the queue.
      • options: Object - The Queue settings which will be applied only to this worker Queue.

Github Actions/Workflows

Triggering a Release

  • Trigger the release workflow via release tag
    git checkout main && git pull
    npm version { minor | major | path }
    git push --follow-tags

License

This project is covered under the MIT license.