Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
Cron jobs do not run in Heroku

I am developing a Nodejs server which I am uploading to Heroku. The file has a Cron job which is meant to run every 4th hour. But when I check in nothing happens. I am using the free version of Heroku and I do not appear to be exceeding my limit of free Dyno hours.

The code in my Index.js file looks like below. As you can see in this simple example, I just want the application to log the time every 4th hour. I also update a variable which should indicate the latest update, which can be used to check for status of updates.

import express from 'express';
const app = express();
import cors from 'cors';
app.use(cors());
import cron from 'node-cron';
import dotenv from 'dotenv'
dotenv.config()
const port = process.env.PORT || 3050;

var lasttime = '';
var task = cron.schedule("0 0 */4 * * *",() => {
        console.log("date: "+Date());
        lasttime = Date();
    }, {
        scheduled: true
    }
 );

app.get('/api_x', async (request, response) => {
reply=lasttime;
response.json({reply:reply});
});

This works fine when I run it on my local computer. When I run it on Heroku it logs the message once, doesn't update the variable lasttime and then does nothing. When I check the logs for the App on Heroku it reads:

Unidling State changed from down to starting Starting process with command npm start webdesign@1.0.0 start /app node index.js listening at 10006 State changed from starting to up

What could be causing my Cron job not to run? (I have also tried using setInterval, but still no results.)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In the free version of Heroku the server sleeps after 30 mins of inactivity, otherwise always on depending on your remaining monthly free dyno hours.

The Hobby plan Never sleeps

Heroku Pricing

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda