A nodejs based, persist by mysql, timely and repeatable task framework;
npm install nodejs-persistable-schedulersh
$ npm install nodejs-persistable-scheduler
`
Dependency:
1. q: A library for promises (CommonJS/Promises/A,B,D);
2. mysql: A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.
Introduction:
This module is a nodejs based, persist by mysql, timely task framework;
There are 4 components that compose the whole module:
$3
Which is repsonsible to doing the initialization works for making the functions of whole module available. In general, the initialization works are sperated into 2 parts: A system initialization task which will create 2 database tables named "fixtimetask" and "scanrecord" in the DB reference that discribed in the configurations; and a customized initialization task which will add maintaining level tasks(not user event triggered tasks, on some other words) if you need any.
This component will be executed ONLY ONCE (Well, actually, you can execute it more than once within some tricky way, referring to the (Best Prectice)[#tests:] please);
$3
Which is responsible to doing 2 steps of fallback work evertime the current instance of nodejs-persistable-scheduler startup: 1. Find out the in-complete executing initialization and maintainess tasks in the last running from the persistance, and run them again; And 2 start the tasks maintainess monitor;
$3
Which is a framework for registering/executing/delaying/hastening/cancelling/pausing/restarting tasks from customers;
$3
Which is responsible to recording the initialization/maintainess task status into persistance while executing.
Best Prectice:
$3
`js
var scheduler = require('nodejs-persistable-scheduler');
var q = require('q');
var methodArr = [];
/*
*
DONT CHANGE THE ORDER of mehtodArr!!!!
JUST PUSH THE NEW ADDED ONES AT THE TAIL!!!
/
method1 = function(param) {
var defer = Q.defer();
//functional codes for method1...
return defer.promise;
};
methodArr.push({name:'METHOD1',method1});
method2 = function(param) {
var defer = Q.defer();
//functional codes for method2...
return defer.promise;
};
methodArr.push({name:'METHOD2',method2});
initialTask = function() {
var defer = Q.defer();
var AM = new Date();
AM.setHours(12,0,0);
scheduler.registerTask("daily",AM,'METHOD1',null,null).then(function(ID) {
if (ID)
{
defer.resolve(true);
}
},function(err) {
defer.reject(err);
});
return defer.promise;
};
var schedulerConfig = {
initFunc: initialTask,
scanInterval: 246060*1000//scan interval time, in MS
};
var initialConfig = {
db:
{
host: '',
user: '',
password: '',
database:'',
port:
},//DB config
methods:methodArr,
scheduler:schedulerConfig
};
scheduler.initialize(initialConfig);
``