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

244
Visualizações
Run cron job in TypeScript NodeJS app whenever deployment to ELB takes place

I'm trying to deploy a app to my ELB server, and trigger a cron job whenever this happens.

Unsure how to make it work? Here is my setup below. Can anybody help?

container.config

container_commands:
  01_remove_cron_jobs:
    command: "rm /etc/cron.d/cron_job || exit 0"
  02_start_cron_jobs:
    command: "cat .ebextensions/batch_job.txt > /etc/cron.d/cron_job && chmod 644 /etc/cron.d/cron_job"
    leader_only: true

batch_job.txt

# The newline at the end of this file is extremely important.  Cron won't run without it.
* * * * * root npm run batch > /dev/null

package.json

"name": "investor-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "nodemon ./src/server.ts",
  "batch": "nodemon ./src/batch/index.ts"
}

./src/batch/index.ts

import cron from 'node-cron';
import {
  fetchHolders,
  fetchTransactions,
  updateHistory,
} from './schedule.batch';
import { logger } from '../services/winston';

(() => {
  cron.schedule('1 * * * *', function () {
    logger.debug('Start fetching holders');
    fetchHolders().then();
  });

  cron.schedule('*/5 * * * *', function () {
    logger.debug('Start fetching transactions');
    fetchTransactions().then();
  });

  cron.schedule('10 * * * *', function () {
    logger.debug('Start updating history');
    updateHistory().then();
  });
})();
about 4 years ago · Juan Pablo Isaza
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