Home > Blockchain >  how to Update status of order in mysql after 30days using sequelize nodejs
how to Update status of order in mysql after 30days using sequelize nodejs

Time:06-15

I have problems is: Auto-update order status if that status doesn't have any update in 30 days.

For example, the current status is " processing" and during 30days later, no more update on this. So the MySQL auto-update order status to "on Hold

I found and guest it something related to Hook, but I don't know how to implement it

CodePudding user response:

depends on how you run you app. I'll suggest using e.g. some cron to get such instances and update it's status.(e.g. https://www.npmjs.com/package/node-cron) Set it for example to run once a day, query such instances depends on build in column updatedAt. Or just to add some other column which will be updated with current date, depends what rules you want to apply

CodePudding user response:

As suggested by Damian you need to use a kind of CRON job which runs everyday to check for expired orders(created more than 30 days ago without any update).

You can use Bull with PM2

Create a processor in Bull and a queue and use the CRON functionality of Bull to set this job to run everyday usually at 12:05 AM or any time you see suitable.

The job would fetch all orders which have status "processing" and were created more than 30 days ago and update them.

Use PM2 to run Bull

CodePudding user response:

you can use cronjob.as npm says Cron is a tool that allows you to execute something on a schedule. for install cron - 'npm i cron'

the (*) shows in order given details.

  • Seconds: 0-59 Minutes: 0-59 Hours: 0-23 Day of Month: 1-31 Months: 0-11 (Jan-Dec) Day of Week: 0-6 (Sun-Sat)

how to initialize cronjob: var CronJob = require('cron').CronJob;

var job = new CronJob(
    '* * * */30 * *',
    function() {
        console.log('every 30 days it is auto updated!');
    },
    null,
    true,
    'America/Los_Angeles'
);

make sure other parameters pass according to your application and also cron use different port then your application.

  • Related