Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda