Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!