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

snowpi-notcron

v0.0.30

Published

Simple persistent intervals module for use with Keystone

Downloads

28

Readme

Snowpi NotCron

Persistent and Non-Persistent interval manager for use with Keystone

Install

npm install snowpi-notcron

//or add to package.json
"dependencies": {
	"snowpi-notcron": "~0.0.x"
}

Use non-persisting intervals

Use a simple object to control your intervals

var notcron = require('snowpi-notcron');


var minute = notcron.simple.setInterval(function(){},2500); //create a new interval
notcron.simple.clearInterval(minute); // clear minute interval
notcron.simple.clearIntervals(); //clear all intervals

console.log(notcron.simple); // all your intervals

Use Persistence

You must set the correct Model to use for persistence and start the saved intervals.

option 1: use a valid mongoose model

var notcron = require('snowpi-notcron');

keystone.start({
	onStart: function() {
		// add any valid mongoose model object
		notcron.init({'model':mongoose.model('Settings')}).start();
	}
);

option 2: use a String value

var notcron = require('snowpi-notcron');

//add a string value to use keystone.list
notcron.set('model','Settings');

keystone.start({
	onStart: function(){
		notcron.init().start();
	}
);

We expect 2 fields: setting and value. Here is a sample Model:

var Settings = new keystone.List('Settings', {
	track:true,
});

Settings.add({
	setting: {type:String, index:true, initial:true },
	value: { type: String,  label:'value', initial:true}
});
Settings.register();
var notcron = require('snowpi-notcron');


var fn = {
    	module: '/path/to/custom/module/sayHello.js',
		fn : 'moduleFunction',
		args: ['arg1','arg2'],
		callback: 'callback',
}

var whenDoneCreatingInterval = function() {
	/**
	* do something 1 time when start succeeds
	* does not run as part of the interval
	* */
	console.log(notcron.persist['minute'])
	
}

//now create the persistent interval
notcron.persist.set(60000,fn,'minute').start(whenDoneCreatingInterval)

persist only accepts string values in the fn Object with exception of args which is an array of String / Boolean values or a String / Boolean value

fn.module can be a path to your own module or an installed node module. To use your own module the path must start with a forward slash /. You can set a base path to be prepended:

notcron.set('baseDir','/home/snowpi/projects/myproject')

fn.fn is the name of a module function you want to run defined as a String

fn.args is a simple array with your function arguments in the order they should be applied.

fn.callback is the name of a module function you want to run as a callback defined as a String

//yields
var module = require (requestedModule)
notcron.persist['minute'] = startInterval(function(){module.moduleFunction('arg1','arg2',module.callback)},60000);

###Interaction

notcron.persist.clear = 'minute'  // kill permanently

var myrepeater = notcron.persist['minute']

myrepeater.kill() // clear now && kill on restart  
myrepeater._interval // interval object/ID
myrepeater.time // interval time
myrepeater.job // 'minute' in our example
myrepeater.programs // Array of functions that will execute

Special non-persistent methods

myrepeater.clear() //kill until restart
myrepeater.join(myFunction) // adds a function to the current interval
myrepeater.scratch(myFunction) // remove a function from interval

Non-persistent methods will not survive a restart