Odin
  • Introduction
  • Why Odin?
  • Key Concepts
    • Environment
      • Environment Type
    • Provisioning
      • Provisioning Config for Component Types
    • Component
      • Available Component Types
      • Component Type reference
        • Optimus Components
          • Aerospike [6.3.0.7-1.0.0]
    • Service
      • Know Your Service Definition
    • Versioning
      • Clearing the Confusion: A Simplified Guide to Artifact, Component, and Service Versions
    • Service Sets
    • Labels
  • Reference
    • CLI reference
  • Onboard Your Service
    • Installation
    • Configure
    • Odin -h
    • Getting Started
    • Create Environment
      • Operations on Environment
    • Service Definition
    • Provisioning Config
    • Deploy Service
    • Release Service
    • Optimus Datastore Operations
      • How to use Optimus Datastore in my service?
      • RDS Operations
      • Aerospike Operations
      • Kafka Operations
    • Operating Service & Components
      • Redeploy
        • In Place Deployment
        • Blue Green Deployment
      • Rolling Restart
      • Adding & removing components
      • Revert a deployment for application component
      • Downscaling a Passive Stack
      • Updating the no. of stacks of application component
    • Dev <> QA iteration
    • Frequently Asked Questions
    • Deploy Concrete Service
    • Undeploy Service
    • Delete Environment
    • Appendix
  • How To
    • Define error threshold for canary deployment
    • Add or Remove a component in an already deployed service
    • Integrate mono-repo(cronjobs) with Odin
    • Deploy crontab with Odin
    • Integrate Data pipeline with Odin
    • Push logs to log central
    • Build artifacts for multi module applications
    • Load test with Odin
    • Track Deployments against Commit Ids
    • Deploy Service on Production - Dream11
    • How and when images are created
    • Check logs for deployed infrastructure - Dream11
    • Onboard Stepfunction as a component
    • Onboard Serverless as a component
    • Login to Kubernetes clusters
  • Release Notes
    • 1.2.0-beta.2 - 11 August, 2022
    • Odin October Release
    • Odin 1.2.0 - Nov 9th 2022
    • Odin February Release
Powered by GitBook
On this page
Export as PDF
  1. How To

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 one start.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:

  1. There is a single build.sh file in the repo which will build the whole repo and put all the files in target/cronjobs directory. This file is as follows:

    rsync -av --exclude='./target' ./ ./target/cronjobs | grep "total"
    cd target/cronjobs && npm install && cd  ../..

    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.

  2. In the resources directory, create a file(say echo-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)

    * * * * * echo "hello" >> /var/cron-logs/echo.log
  3. 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:

    #!/usr/bin/env bash
    set -e
    echo "APP_DIR: ${APP_DIR}"
    echo "ENV: ${ENV}"
    echo "VPC_SUFFIX: ${VPC_SUFFIX}"
    echo "TEAM_SUFFIX: ${TEAM_SUFFIX}"
    echo "SERVICE_NAME: ${SERVICE_NAME}"
    echo "NAMESPACE:" ${NAMESPACE}
    
    envsubst < ${APP_DIR}/resources/echo-cron-schedule.txt > /tmp/crontab.txt
    crontab /tmp/crontab.txt
    
    if [[ "$DEPLOYMENT_TYPE" == "container" ]]; then
      cron  # start cron service inside containers
    fi
    
    tail -f ${APP_DIR}/resources/echo-cron-schedule.txt
  4. 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. The start_script_path is responsible for running the required jobs.

    {
      "name": "cronjobs",
      "version": "1.0.0-SNAPSHOT",
      "team": "test",
      "components": [
        {
          "name": "cronjobs",
          "type": "application",
          "version": "1.0.1-SNAPSHOT",
          "config": {
            "build_type": "node",
            "build_version": "14.15.1-buster-slim",
            "start_script_path": ".odin/echo-start.sh",
            "discovery": "none"
          }
        }
      ]
    }
  5. Deploy the service as usual.

PreviousAdd or Remove a component in an already deployed serviceNextDeploy crontab with Odin

Last updated 1 year ago

Refer to PR for reference.

Also, note that the start script will be more complex for actual cron-jobs. Please refer to the start.sh in PR.

this
this