bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 244 forks source link

Implementing scheduler to keep syncing database #217

Open Zalasanjay opened 7 years ago

Zalasanjay commented 7 years ago

Hello friends, I've implement scheduler for sync database as per users requirement like user can set as "at 5:00 pm on Weds,Thurs and Fri" or something else like that.

I've configure my later.js code when the user create connection for any database and that time only my scheduler will execute. if user create database connection and my keep_sync scheduler starts. after that if my server restart then what will happen my keep_sync scheduler will also restart or i have to manually need to execute it again?

var http = require('http');
var express = require('express');
var later = require('later');
var app = express();
var port = Number(2200);

later.date.UTC();
later.date.localTime();

var server = http.createServer(app).listen(port, function () {
    console.log('App Runnings on: ', port);
})

var keep_sync = later.parse.text("at 5:00 pm on Weds,Thurs and Fri");
later.setInterval(syncDb, keep_sync);

function syncDb() {
    // my database sync code appends here
} 

Any suggestions how it can be accomplished with later.js?