---
# Source: airflow/templates/configmap-scripts.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: airflow-scripts
  labels:
    app: airflow
    chart: airflow-5.2.0
    release: airflow
    heritage: Tiller
data:
  install-requirements.sh: |
    #!/bin/sh -e
    if [ ! -d /usr/local/airflow/dags ]; then
      echo "No folder /usr/local/airflow/dags"
      exit 0
    fi
    cd /usr/local/airflow/dags
    if [ -f requirements.txt ]; then
      pip install --user -r requirements.txt
    else
      exit 0
    fi
  stop-worker.sh: |
    #!/bin/sh -e
    celery -b $AIRFLOW__CELERY__BROKER_URL -d celery@$HOSTNAME control cancel_consumer default

    # wait 10 second before checking the status of the worker
    sleep 10

    while (( $(celery -b $AIRFLOW__CELERY__BROKER_URL inspect active --json | python -c "import sys, json; print(len(json.load(sys.stdin)['celery@$HOSTNAME']))") > 0 )); do
    sleep 60
    done