#
# Celery configuration file
# See: http://docs.celeryproject.org/en/latest/userguide/configuration.html
#

from celery.schedules import crontab

# Broker settings

import ssl
broker_url = "amqps://bodhi{{ env_suffix }}:@rabbitmq{{ env_suffix }}.fedoraproject.org//bodhi"
broker_login_method = "EXTERNAL"

# Contrary to what the docs says, we can't define SSL options in broker_use_ssl, or the ssl_version
# will be ignored and we need to force TLS1.2. I will report that bug ASAP. A workaround is to use
# broker_transport_options.

broker_use_ssl = True

# Avoid the task to hang forever if the rabbitmq broker is down
# https://github.com/celery/celery/issues/4627#issuecomment-396907957
broker_transport_options = {
    "ssl":
    {
        "ca_certs": "/etc/pki/fedora-messaging/cacert.pem",
        "keyfile": "/etc/pki/fedora-messaging/bodhi-key.pem",
        "certfile": "/etc/pki/fedora-messaging/bodhi-cert.pem",
        "cert_reqs": ssl.CERT_REQUIRED,
        "ssl_version": ssl.PROTOCOL_TLSv1_2,
    },
    "max_retries": 3,
    "interval_start": 0,
    "interval_step": 0.2,
    "interval_max": 0.5
}

# Where the tasks are defined
imports = "bodhi.server.tasks"

# Send back tasks results so we can wait for them
result_backend = 'rpc://'
result_persistent = True

# Task routing
task_routes = {
    # Route the following tasks to a specific queue that will only be run on
    # hosts that have a Koji mount.
    'compose': {'queue': 'has_koji_mount'},
    'clean_old_composes': {'queue': 'has_koji_mount'},
}

# Periodic tasks
beat_schedule = {
    "approve-testing": {
        "task": "approve_testing",
        "schedule": 3 * 60,  # every 3 minutes
    },
    "check-policies": {
        "task": "check_policies",
        "schedule": 60 * 60,  # every hour
    },
    "check-signed-builds": {
        "task": "check_signed_builds",
        "schedule": crontab(hour=2, minute=33),
    },
    "clean-old-composes": {
        "task": "clean_old_composes",
        "schedule": crontab(hour=3, minute=3),
        "kwargs": {"num_to_keep": 10},
    },
    "expire-overrides": {
        "task": "expire_overrides",
        "schedule": 60 * 60,  # every hour
    },
}

beat_schedule_filename = "/tmp/celery-beat-schedule"
