---
- name: Configure activity tracking job
  ansible.builtin.cron:
    name: Activity tracking
    cron_file: activity-tracking
    minute: "*/5"
    user: root
    job: >-
      flock -n /var/lock/activity_tracking.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/activity_tracking/run_job_tracker.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure authorisation job
  ansible.builtin.cron:
    name: Authorisation
    cron_file: authorisation
    minute: "00"
    hour: "3"
    user: root
    job: >-
      flock -n /var/lock/authorisation.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/authorisation/run.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure cache company data job
  ansible.builtin.cron:
    name: Cache company data
    cron_file: cache-company-data
    minute: "00"
    hour: "4"
    user: root
    job: >-
      flock -n /var/lock/cache_company_data.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/cache_company_data/cache_company_data.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure WFI metadata update job
  ansible.builtin.cron:
    name: WFI metadata update
    cron_file: wfi-metadata-update
    minute: "*/10"
    user: root
    job: >-
      flock -n /var/lock/wfi_metadata_update.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/wfi_metadata_update/wfi_metadata_update.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure generate batch reports job
  ansible.builtin.cron:
    name: Generate batch reports
    cron_file: generate-batch-reports
    minute: "00"
    hour: "1"
    user: root
    job: >-
      flock -n /var/lock/generate_batch_reports.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/generate_batch_reports/generate_batch_reports.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure compute ML Accuracy job
  ansible.builtin.cron:
    name: Compute ML Accuracy
    cron_file: compute-ml-accuracy
    minute: "00"
    hour: "0"
    user: root
    job: >-
      flock -n /var/lock/compute_accuracy.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/compute_accuracy/run.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure WFI periodic R segment migration job
  ansible.builtin.cron:
    name: WFI periodic R
    cron_file: wfi-periodic
    minute: "30"
    hour: "5"
    user: root
    job: >-
      flock -n /var/lock/wfi_periodic_r.lock
      -c "bash {{ octopus_dir }}/data/wfi_loader/load_wfi.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure WFI periodic W segment migration job
  ansible.builtin.cron:
    name: WFI periodic W
    cron_file: wfi-periodic-w
    minute: "30"
    hour: "4"
    user: root
    job: >-
      flock -n /var/lock/wfi_periodic_w.lock
      -c "bash {{ octopus_dir }}/data/wfi_loader/load_wfi_periodic_w.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env in ['PROD', 'DR'] and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure redis snapshot create job
  ansible.builtin.cron:
    name: Redis snapshot create
    cron_file: redis-snapshot-create
    minute: "00"
    hour: "22"
    user: root
    job: >-
      flock -n /var/lock/redis_snapshot_create.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/redis_snapshot/create_snapshot.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env == 'PROD' and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure redis snapshot restore job
  ansible.builtin.cron:
    name: Redis snapshot restore
    cron_file: redis-snapshot-restore
    minute: "00"
    hour: "23"
    user: root
    job: >-
      flock -n /var/lock/redis_snapshot_restore.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/redis_snapshot/restore_snapshot.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env == 'DR' and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure elasticsearch snapshot create job
  ansible.builtin.cron:
    name: Elasticsearch snapshot create
    cron_file: elasticsearch-snapshot-create
    minute: "00"
    hour: "23"
    user: root
    job: >-
      flock -n /var/lock/elasticsearch_snapshot_create.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/es_snapshot/create_snapshot.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env == 'PROD' and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )

- name: Configure elasticsearch snapshot restore job
  ansible.builtin.cron:
    name: Elasticsearch snapshot restore
    cron_file: elasticsearch-snapshot-restore
    minute: "00"
    hour: "00"
    user: root
    job: >-
      flock -n /var/lock/elasticsearch_snapshot_restore.lock
      -c "bash {{ octopus_dir }}/scheduled_jobs/es_snapshot/restore_snapshot.sh"
      > /dev/null
  when: >
    env not in ['PROD', 'DR'] or
    (
      env == 'DR' and
      (
        ansible_hostname.endswith('3') or
        ansible_hostname.endswith('C')
      )
    )
