Merge pull request #1944 from castrapel/celery_tasks_sync
Celery task for sync job
This commit is contained in:
commit
f824f76d9c
|
@ -19,7 +19,7 @@ from lemur.factory import create_app
|
||||||
from lemur.notifications.messaging import send_pending_failure_notification
|
from lemur.notifications.messaging import send_pending_failure_notification
|
||||||
from lemur.pending_certificates import service as pending_certificate_service
|
from lemur.pending_certificates import service as pending_certificate_service
|
||||||
from lemur.plugins.base import plugins
|
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()
|
flask_app = create_app()
|
||||||
|
|
||||||
|
@ -188,3 +188,26 @@ def clean_source(source):
|
||||||
"""
|
"""
|
||||||
current_app.logger.debug("Cleaning source {}".format(source))
|
current_app.logger.debug("Cleaning source {}".format(source))
|
||||||
clean([source], True)
|
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)
|
||||||
|
|
|
@ -93,6 +93,7 @@ def sync(source_strings):
|
||||||
)
|
)
|
||||||
|
|
||||||
sentry.captureException()
|
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})
|
metrics.send('source_sync', 'counter', 1, metric_tags={'source': source.label, 'status': status})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue