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

hot-sauce

v1.0.7

Published

Api Component to SpiceRack responsible for managing Scheduled Jobs in CouchBase

Downloads

20

Readme

Hot Sauce

Couchbase Backed Job Scheduling Management API

Build Status Coverage Status npm

Installation

npm install hot-sauce

Testing

npm run test

Code Coverage

Code Coverage provided by Istanbul with hooks for coveralls. To see coverage report run

npm run cover

Usage - built-in start/stop methods

This module can be incorporated into an existing application with applicable start/stop commands

var HotSauce = require('hot-sauce');

var config = {
    port: 3000,
    couchbase: {
        cluster: ['http://couchbase.host:8091'],
        bucket: {
            name: 'bucket_name',
            password: 'p@$$w0rd'
        }
    },
    logger: {
        console: {enabled: true, options: {level: 'debug'}},
        file: {enabled: false, options: {level: 'debug', filename: "hot-sauce.log"}}
    }
};

var hotSauce = new HotSauce(config);

hotSauce.start();

Usage - subapp in existing app

This module can be incorporated into an existing application as a sub-app

var HotSauce = require('hot-sauce');

var config = {
    port: 3000,
    couchbase: {
        cluster: ['http://couchbase.host:8091'],
        bucket: {
            name: 'bucket_name',
            password: 'p@$$w0rd'
        }
    },
    logger: {
        console: {enabled: true, options: {level: 'debug'}},
        file: {enabled: false, options: {level: 'debug', filename: "hot-sauce.log"}}
    }
};

var hotSauce = new HotSauce(config);

var app = express();
//require an apiKey on all routes
app.all('*', function(req, res, next) {
    if(req.query.apiKey) {
        next();
    } else {
        res.status(400).json({error: 'apiKey is required'});
    }
});

//mount the hot sauce app at /api/
app.use('/api', hotSauce.app);

//start server
var server = http.createServer(app);
server.listen(config.port);

Configuration

{
    port: 3000, //port for server to listen on
    couchbase: { 
        cluster: ['http://couchbase.host:8091'],  //array of cochbase cluster nodes
        bucket: {
            name: 'bucket_name',  //bucket to use for storage
            password: 'p@$$w0rd'
        }
    },
    logger: { 
        console: {enabled: true, options: {level: 'debug'}},
        file: {enabled: false, options: {level: 'debug', filename: "hot-sauce.log"}}
    }
};

Couchbase Configuration

The application requires the existence of 2 views in the bucket

GetAllJobs

function (doc, meta) {
  emit(meta.id, doc);
}

GetJobIfAvailable

function (doc, meta) {
  if(doc.isActive === null || doc.isActive === undefined || doc.isActive === true){
    if(doc.locking && doc.locking.locked != true){
      if(doc.schedule && doc.schedule.future_instances.length > 0){
      //only find unlocked jobs
        var instances = doc.schedule.future_instances;
        for(var i=0; i<instances.length; i++){
          var key = dateToArray(instances[i]);
      emit(key, doc.code);
        }
      } 
    }
  }
}

GetJobsMaintenance

function (doc, meta) {
  var key = [];
  key.push(doc.locking ? doc.locking.locked : false);
  key.push(doc.id);
  emit(key, doc);
}

Routes

  • GET /jobs Index of all jobs stored in couchbase ** Example Response
{
    "id": "52",
    "name": "job",
    "code": "code_52",
    "description": "desc",
    "jobData": {},
    "isActive": true,
    "schedule": {
        "expirationThreshold": 20000,
        "cron": "*/12 52 * * * *",
        "future_instances": [
            "2015-08-03T19:52:00.000Z",
            "2015-08-03T19:52:12.000Z",
            "2015-08-03T19:52:24.000Z",
            "2015-08-03T19:52:36.000Z",
            "2015-08-03T19:52:48.000Z"
        ]
    },
    "locking": {},
    "lastModified": "2015-08-03T19:06:55.502Z"
}
  • GET /jobs/:id Detail on specific job

  • GET /jobs/available?codes=code1,code2,code3&caller=someone Given input codes, get & lock an available job by someone. Margin of error for the query is 5 seconds i.e it is feasible to get a job scheduled to run upto 5 seconds in the future.

  • GET /jobs/:id/unlock?caller=someone
    Unlocks a locked job

  • POST /jobs Create/Upload a job ** Example POST request

{
    "id": "52",
    "name": "job",
    "isActive": false,
    "code": "every52nd",
    "description": "desc",
    "jobData": {},
    "schedule": {
        "expirationThreshold": 20000,
        "cron": "*/12 52 * * * *"
    },
    "locking": {}
}