From 56ed416cb7664f20a7bd28dfb517f9183cc64cd5 Mon Sep 17 00:00:00 2001 From: Curtis Castrapel Date: Mon, 29 Oct 2018 09:10:43 -0700 Subject: [PATCH] Celery task for sync job --- lemur/common/celery.py | 25 ++++++++++++++++++++++++- lemur/sources/cli.py | 1 + requirements-docs.in | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lemur/common/celery.py b/lemur/common/celery.py index 8dbb6c29..c12c6f06 100644 --- a/lemur/common/celery.py +++ b/lemur/common/celery.py @@ -19,7 +19,7 @@ from lemur.factory import create_app from lemur.notifications.messaging import send_pending_failure_notification from lemur.pending_certificates import service as pending_certificate_service from lemur.plugins.base import plugins -from lemur.sources.cli import clean, validate_sources +from lemur.sources.cli import clean, sync, validate_sources flask_app = create_app() @@ -188,3 +188,26 @@ def clean_source(source): """ current_app.logger.debug("Cleaning source {}".format(source)) clean([source], True) + + +@celery.task() +def sync_all_sources(): + """ + This function will sync certificates from all sources. This function triggers one celery task per source. + """ + sources = validate_sources("all") + for source in sources: + current_app.logger.debug("Creating celery task to sync source {}".format(source.label)) + sync_source.delay(source.label) + + +@celery.task() +def sync_source(source): + """ + This celery task will sync the specified source. + + :param source: + :return: + """ + current_app.logger.debug("Syncing source {}".format(source)) + sync([source], True) diff --git a/lemur/sources/cli.py b/lemur/sources/cli.py index 1f2fd9b0..0ab8c9f8 100644 --- a/lemur/sources/cli.py +++ b/lemur/sources/cli.py @@ -93,6 +93,7 @@ def sync(source_strings): ) sentry.captureException() + metrics.send('source_sync_fail', 'counter', 1, metric_tags={'source': source.label, 'status': status}) metrics.send('source_sync', 'counter', 1, metric_tags={'source': source.label, 'status': status}) diff --git a/requirements-docs.in b/requirements-docs.in index cf598240..d04d510b 100644 --- a/requirements-docs.in +++ b/requirements-docs.in @@ -4,4 +4,4 @@ -r requirements.txt sphinx sphinxcontrib-httpdomain -sphinx-rtd-theme \ No newline at end of file +sphinx-rtd-theme