1

How can we schedule our job in node.js? Is there any way to achieve this? Is there any way except cron job?

We have a tender model and want to change status after closing date has passed.

Which way would be best?

module.exports = function(sequelize, DataTypes) {
var SpreeOpenTenders = sequelize.define(
  "SpreeOpenTenders",
  {
    tender_name: {
      type: DataTypes.STRING
    },
    created_by: {
      type: DataTypes.STRING
    },
    tender_closing_date: {
      type: DataTypes.DATE
    },
    announcement_date: {
      type: DataTypes.DATE
    },
    expected_delivery_date: {
      type: DataTypes.DATE
    },
    state: {
      type: DataTypes.STRING,
      defaultValue: "Open",
      comment: "Open, On going, Bid selection, Completed"
    }
  }
);
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Pradip Bhuvani
  • 427
  • 1
  • 4
  • 18

2 Answers2

0

You can use node-scheduler, check the link: https://www.npmjs.com/package/node-schedule

Pushpendra Kumar
  • 1,721
  • 1
  • 15
  • 21
0

There are some techniques through which we can derive a value depending on another value in a Schema. But that case is only triggered on data update or creation. So, this method will not be useful in your scenario.

So, according to my knowledge, you cannot avoid cron job. The thing you can do is look for a Node.js cron job scheduler that requires minimal resources to execute. One of the scheduler that i personally use is cron.

Hope this will help you.

Muhammad Zeeshan
  • 4,608
  • 4
  • 15
  • 41