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

martinet

v1.0.3

Published

Distributed job queue

Downloads

9

Readme

Martinet

Distributed task management.

Martinet is a database-backed, zeroMQ-based distributed task management system. It is persistent with respect to future and recurring tasks, so if your system goes down, those tasks will be unaffected. Martinet can use any sequelize.js compatible database as its backing database (SQLite is used by default).

Martinet uses a push-pull messaging pattern to ensure efficiency when used in a distributed environment.

Installation

npm install martinet

Usage

This library is divided into two parts: the Martinet object, which handles dispatching and scheduling tasks, and the Worker object which receives said tasks and defines the actions to take upon being given certain tasks.

Martinet

Setup

var Martinet = require('martinet');

var martinet = new Martinet();

// Martinet allows you to create multiple workers
// so that you can keep worker code in separate 
// logical modules.

martinet.addWorker('WORKER_NAME_1', 'WORKER_PORT_1');
martinet.addWorker('WORKER_NAME_2', 'WORKER_PORT_2');

Creating Tasks

Execute a task immediately

martinet.execute({
    worker: 'WORKER_NAME',
    name: 'task_name',
    description: 'Do a thing' // Used in the backend so it's easier to lookup tasks later
}, args);

// args JSON object of named arguments, so like
// {
//    thing_id: 1   
// }
//
// this object gets serialized and passed to the Worker
//
Execute a task in the future

martinet.schedule('in 20 minutes', {
    worker: 'WORKER_NAME',
    name: 'task_name',
    description: 'Do a thing in 20 minutes'
}, args);
Create a recurring task

martinet.every('30 minutes', {
    worker: 'WORKER_NAME',
    name: 'task_name',
    description: 'Do a thing every half hour',
    run_at: 'midnight' // optional time to start the recurring task
}, args);

Workers

Setup


var MartinetWorker = require('martinet').Worker;

var WORKER_PORT = 3000;
var worker = new MartinetWorker(WORKER_PORT, {
    martinet_url: '127.0.0.1',
    martinet_port: '8089'
});

Defining Tasks


worker.on('task_name', function(taskId, data, callback) {
    // do a thing.
    
    // if it's successful, callback(),
    // if there's an error, callback(err)

});

Options

Martinet

Port

Custom port for martinet's pull socket to listen on.

var Martinet = require('martinet');

var options = {
    port: 8009
};

var martinet = new Martinet(options);

DB

Connection information to the backing database. Uses sequelize.js options.

default is

var Martinet = require('martinet');

var options = {
    db: {
      database: 'martinet-db',
      username: process.env.USER,
      password: null,
      options: {
        dialect: 'sqlite',
        storage: 'martinet.db',
        logging: false,
        omitNull: true
      },
      sync: true
    }
};

var martinet = new Martinet(options);

but for example to use postgres:

var Martinet = require('martinet');

var options = {
    db: {
      database: 'martinet-db',
      username: process.env.USER,
      password: null,
      options: {
        dialect: 'postgres',
        port: 5432,
        host: 'database.host'
        logging: false,
        omitNull: true
      },
      sync: true
    }
};

var martinet = new Martinet(options);

Worker

Martinet URL

Connection string to connect to martinet. If worker is on the same machine as martinet, this should be 127.0.0.1

Martinet PORT

The port to connect to martinet on. This should be the same port defined by the martinet object's port option.