Restart or kill jobs when deploying to server
See original GitHub issueThe library works perfectly but I had a question with regards to creation of the cron jobs.
I am currently deploying the node app to an ec2 instance by first building the app and then running node app.js
which starts the server.
When I re-deploy the app ie, re-build and re-run node app.js
, will it overwrite existing jobs on the server or will it create new jobs?
Currently the app.ts
looks like this
import express, { Application, Request, Response, NextFunction } from "express";
import { schedulePeriodicCheckJob } from "./utils/cronHelper";
/*** More commands ***/
schedulePeriodicCheckJob();
/*** More commands ***/
app.use(router);
export default app;
cronHelper.ts
import cron from "cron";
const CronJob = cron.CronJob;
export const schedulePeriodicCheckJob = () => {
const job = new CronJob(
"1 1 */1 * * *", // run every 1 hour
() => {
// const d = new Date();
console.log("on Tick:");
// long running task
},
() => {
console.log("on Complete");
},
true
);
};
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Background jobs and deploys - Kir Shatrov
Have you ever wondered what happens with a running background job in Sidekiq or Resque when you deploy new version of code and...
Read more >Restart supervisor during deploy? - Laracasts
The queue:restart command will stop all of the queue workers running on the machine and let Supervisor restart them, ensuring they are using...
Read more >Killing Workers Early & on Deploy - SymfonyCasts
Restarting the worker is handled by Supervisor and doesn't take a huge amount of resources. All of these options cause the worker to...
Read more >Start Delayed Job on boot and restart on deploy
This step is kind of a preparation for the next step when we need to restart on deploy. The delayed job service that...
Read more >Starting, stopping, and restarting Application Servers
To stop a specific Application Server · In the BMC Server Automation Console, from the Configuration menu, select Infrastructure Management.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So, that’s a little complicated. In part it depends on your code. If you instantiate the job every time the node process starts up then the job will start up every time you start up a node process. The node process is killed, it’s just that nodemon runs and manages child processes afaik. So, nodemon will kill that child process, or watch for it to die, then it starts a new process. This should restart your cron instantiations. I’m using pm2 locally and this is how it works for me.
So, the short answer is, nodemon should kill the prior process and cron jobs with it, and then the new process would instantiate replicas assuming you’re instantiating them on startup of the code.
Does that make sense?
Awesome. Glad I could help.