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

peonify

v1.1.2

Published

A class library for implementing background task services in a neat and standardized fashion

Downloads

3

Readme

Peonify

Peonify is a background service handler designed to help make the design of distributed systems easier.

Core Concepts

The Queue

A queue is the core concept of Peonify. A queue is a list of tasks to be handled by THIS PROCESSOR.

As Peonify is designed to be inherently scalable in its runtime, it is important to understand that the queue represents the set of tasks that this processor will attempt to complete.

The Tasks

A queue is made up of tasks. Each task represents a discreet unit of activity which should be executed by the processor.

A task will not necessarily be executed as soon as it is added to a queue, so tasks must be redundant towards multiple execution.

The TaskLists

A task list is an execution for a type of task. It provides a specialized implementation for the generic information provided by the Task format.

The Streams

Each peonify instance has a list of attached streams. Streams are essentially plugins that submit Tasks to the Queue.

They can provide a custom interface for any inbound method required, such as database polling, webhooks, websockets, or message queues.

Getting Started

  1. Create an instance of Peonify as follows. This serves as the queue.

index.js

var Peonify = require('peonify')

var taskQueue = new Peonify()
  1. Next you will need to add a task list to your peonify instance. This takes the form of a dictionary (javascript object) mapping the type as a string, to an implementation.

index.js

var taskList = {
    "email-task": require('./emailTask')
}

taskQueue.addTaskList(taskList)

emailTask.js

var Task = require('peonify').TaskImplementation

class EmailTask extends TaskImplementation {

    constructor(metaData) {
        super(metaData)
        // MetaData is store in this.metaData for access. It contains all the data that the specialized implementation
        //  requires to complete its duties
    }

    *execute() {
        // Send an email here. This function is run using the co library, so asynchronous actions can be yielded for flow control.
    }

}

module.exports = EmailTask
  1. Add a stream so that tasks can flow into the queue

index.js

var simpleTaskGenerator = require('./task-generator.js')

taskQueue.addStream(simpleTaskGenerator)

task-generator.js

var Stream = require('peonify').Stream,
    Task = require('poenify').Task

class TaskGenerator extends Stream {

    *poll() {
        // When this method is called, some actions should be taken and either a task, in the generic JSON format
        //  or false, in the event no task is available, should be returned.

        // The method will be called periodically by the processor when the queue is becoming depleted.

        return new Task(...,...,...)
    }

    *notifyComplete() {
        // This task allows notification that a particular task has been succesfully completed.
        // This function is particularly useful when working with a message queue that has integrated retries.
        // No return is expected
    }

}
  1. Run the task queue

To begin handling tasks, run the beginProcessing function.

index.js

taskQueue.beginProcessing()

The task queue will then run until the program receives a SIGTERM event. At that stage, the queue will cease to poll its streams and gracefully end all tasks within its queue.