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();
});
})();