wahengchang / nodejs-cron-job-must-know Goto Github PK
View Code? Open in Web Editor NEWit is an example of running node.js script with every certain period(cron job)
it is an example of running node.js script with every certain period(cron job)
I have written a cron job as given below
var cron = require('node-cron');
var taskMap = {};
let job = cron.schedule('*/1 * * * * ', ()=>{
var shell = require('./utils/child_helper');
var commandList = [
"node *****",
"node *****",
"node ******"
]
shell.series(commandList , function(err,res){
// console.log('executed many commands in a row');
console.log('done')
});
});
which need to run on every 1 min but the scripts inside the cron may take more than 1 min.
I need to skip the cron for the moment when the scripts are still running .
Can anyone help me on it.
Calling cron from app.js as below code
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
var port = 3000;
require('./cronController').job.start();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.listen(port , ()=>{
let dateTime = new Date();
let message = 'Server is running on Port :- ' + port + ' started at :- ' + dateTime;
console.log(message);
});
//exceute every 2:30am morning
// cron.schedule('30 2 * * *', function(){
// console.log('running a task every two minutes');
// });
//exceute every 1 min
exceute --> execute
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.