Integrate mono-repo(cronjobs) with Odin
(How to integrate cron-jobs in https://github.com/dream11/cronjobs with Odin)
Points to note:
The repo
cronjobs
has many cron-jobs in the form of single.js
files. We don't need to treat all of them as separate applications. We'll treat them as one application and have a single artifact for the whole repo.However, we'll usually only need to run a subset of them at once. Therefore, there will be multiple
start
scripts instead of only onestart.sh
as exists for other applications.All jobs will be run via crontab.
Keeping the above points in mind, these are the steps to follow to integrate a cronjob in the repo with odin:
There is a single
build.sh
file in the repo which will build the whole repo and put all the files intarget/cronjobs
directory. This file is as follows:Since, this will be used for all the jobs, we need to make sure it does everything everyone would need. If the above file doesn't work for your specific case, please create an issue in the repo.
In the
resources
directory, create a file(sayecho-cron-schedule.txt
) containing the schedules for each of the cronjobs to run. For example if there is a single job to run, the file will have single line for a single schedule as follows: (This is a dummy job which appends hello to a file)Create a start script with a name which can be used to identify which cron-jobs it will be used to run. This will have to code to execute to register the above cron-schedules with crontab. For example, to run the above cron, create a file
echo-start.sh
in the.odin/cronjobs
directory with the following code:In the service-definition file, add the component for cron as follows: Note here that the name of the component must necessarily be
cronjobs
as that is used to get the artifact and there is only one artifact for the whole repo. Thestart_script_path
is responsible for running the required jobs.Deploy the service as usual.
Last updated