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

anytv-kue

v1.0.1

Published

kue wrapper for any.tv

Downloads

32

Readme

anytv-kue

Kue Helper for setup and cleanup of Kue

Changes to be made to old codes

  1. Replace all require('kue'); with

  2. NOTE: Define namespace when calling createQueue to ensure properly scheduling for multiple applications. ex

        const kue = require('anytv-kue')();
        const queue = kue.createQueue({
            prefix: 'namespace'
        });

Added features

  • Setup kue

    // server.js (before)
    const kue = require('anytv-kue')();
    const queue = kue.createQueue();
    
    function start () {
        /* server code */
    }
    
    queue.on('error', err => {
        winston.log('error', 'QUEUE ERROR:', err);
    });
    
    process.once('SIGTERM', sig => {
        winston.log('SIGTERM', sig);
        queue.shutdown(5000, err => {
            winston.log('error', 'Kue shutdown:', err );
            process.exit(0);
        });
    });
    
    queue.active((err, ids) => {
        ids.forEach(id => {
            kue.Job.get(id, (_err, job) => {
                job.inactive();
            });
        });
    });
    
    queue.inactive((err, ids) => {
        ids.forEach(id => {
            kue.Job.get(id, (_err, job) => {
                job.inactive();
            });
        });
    });
    
    start();
    
    // server.js (now)
    const kue = require('antv-kue')();
    const queue = kue.createQueue();
    
    function start () {
        /* server code */
    }
    
    kue.setup(queue);
    
    start();
    
  • Activate UI

        const kue = require('anytv-kue')();
        const queue = kue.createQueue({remove_on_complete:false});
        const express = require('express');
        const app = express();
    
        //activates UI without auth in `/kue`
        kue.activateUI(app)();
        //activates UI in route `/kueapp` without auth
        kue.activateUI(app)('/kueapp');
        //activates UI with basic auth in `/kue`
        kue.activateUI(app, 'username', 'password')();
        //activates UI with basic auth in `/kueapp`
        kue.activateUI(app, 'username', 'password')('/kueapp');
        //activates UI with custom middleware in `/kue`
        kue.activateUI(app, middleWare)();
        //activates UI with custom middleware in `/kueapp`
        kue.activateUI(app, middleWare)('/kueapp');
  • Default Title

        const kue = require('anytv-kue')();
        const queue = kue.createQueue();
    
        queue.create('jobtitle', { test: 123 })
            .save(); //default title will be "{ test: 123 }"
    
        queue.create('jobtitle', { test: 123, title: '123'})
            .save(); //title will be "123"
    
        queue.create('jobtitle')
            .save(); //title will be "undefined"
  • Cleanup jobs

        kue.cleanup(job_type, status);
  • Remove jobs on complete

      // before
      const kue = require('kue');
      const queue = kue.createQueue();
    
      queue.create('name', {})
        .removeOnComplete(true)
        .save();
    
      queue.create('name2', {})
        .removeOnComplete(true)
        .save();
      //now
      const kue = require('anytv-kue')({shutdownTimer: 10000});
      const queue = kue.createQueue({remove_on_complete: true});
    
      queue.create('name', {})
        .save();
    
      queue.create('name2', {})
        .save();
  • fixed_doubling and delay_doubling custom backoffs

    • fixed_doubling - starts at 2 minutes, then 4, then 8, etc
    • delay_doubling - starts at initial_delay * 2 (2 seconds if no initial delay)
        const kue = require('anytv-kue')();
        const queue = kue.createQueue();
    
        queue.createJob('jobtitle', { test: 123 })
            .backoff('fixed_doubling')
            .save(); // next delay will be 2 minutes
            
        queue.createJob('jobtitle', { test: 123 })
            .delay(1000 * 10) // 10 seconds
            .backoff('delay_doubling')
            .save(); // next delay will be 20 seconds
            
        queue.createJob('jobtitle', { test: 123 })
            .backoff('delay_doubling')
            .save(); // next delay will be 2 seconds

Available configurations

constructor

  • shutdownTimer - time alotted for graceful shutdown

options

  • remove_on_complete - will Kue remove data from redis when job is complete
  • for other options, check out: https://github.com/lykmapipo/kue-scheduler#options

setup

kue.setup(queue, callbacks);
  • queue - the queue we want to listen to (usually the return of kue.createQueue)
  • callbacks - there are 5 callbacks available
    {
      //called when there is an error in redis queue
      error: function (err) {
    
      },
    
      //called when a job failed altogethere after alotted attempts
      failed: function (jobid) {
    
      },
    
      //called when a process SIGTERM occurs
      sigterm: function (sig) {
    
      },
    
      //called upon setup, control what you want to do with active jobs
      active: function (err, ids) {
    
      },
    
      //called upon setup, control what you want to do with inactive jobs
      inactive: function (err, ids) {
    
      }
    }

#How To's

Update Delayed jobs

    'use strict';

    const kue = require('kue');
    const queue = kue.createQueue();

    queue.delayed(function (err, selectedJobs) {
        selectedJobs.forEach(function (id) {
            kue.Job.get(id, function (err, job) {
                if (!job.removeOnComplete()) {
                    job.removeOnComplete(true).update();
                }
            });
        });
    });

.update() on a Job object will update it. this is an undocumented of Kue

Contributing Guidelines

Please read CONTRIBUTING.md