Giter Site home page Giter Site logo

wahengchang / nodejs-cron-job-must-know Goto Github PK

View Code? Open in Web Editor NEW
38.0 6.0 15.0 7 KB

it is an example of running node.js script with every certain period(cron job)

JavaScript 100.00%
nodejs javascript cron cron-jobs cronjob reactjs scheduler schedule example tutorial

nodejs-cron-job-must-know's Issues

Need help in skipping cronjob when already scripts for previous cronjob are running

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);
});

Misspelling

//exceute every 2:30am morning
// cron.schedule('30 2 * * *', function(){
// console.log('running a task every two minutes');
// });

//exceute every 1 min

exceute --> execute

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.