question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Restart or kill jobs when deploying to server

See original GitHub issue

The 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ncb000gtcommented, Mar 14, 2019

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?

0reactions
ncb000gtcommented, Mar 14, 2019

Awesome. Glad I could help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found