0.0.30 • Published 10 years ago

snowpi-notcron v0.0.30

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

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

0.0.30

10 years ago

0.0.29

10 years ago

0.0.28

10 years ago

0.0.27

10 years ago

0.0.26

10 years ago

0.0.25

10 years ago

0.0.24

10 years ago

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago