示例#1
0
文件: celery.py 项目: Netflix/lemur
def sync_source(source):
    """
    This celery task will sync the specified source.

    :param source:
    :return:
    """

    function = "{}.{}".format(__name__, sys._getframe().f_code.co_name)
    task_id = celery.current_task.request.id
    log_data = {
        "function": function,
        "message": "Syncing source",
        "source": source,
        "task_id": task_id,
    }
    current_app.logger.debug(log_data)

    if is_task_active(function, task_id, (source,)):
        log_data["message"] = "Skipping task: Task is already active"
        current_app.logger.debug(log_data)
        return
    sync([source])
    log_data["message"] = "Done syncing source"
    current_app.logger.debug(log_data)
示例#2
0
文件: celery.py 项目: jramosf/lemur
def sync_source(source):
    """
    This celery task will sync the specified source.

    :param source:
    :return:
    """

    function = "{}.{}".format(__name__, sys._getframe().f_code.co_name)
    task_id = celery.current_task.request.id
    log_data = {
        "function": function,
        "message": "Syncing source",
        "source": source,
        "task_id": task_id,
    }
    current_app.logger.debug(log_data)

    if is_task_active(function, task_id, (source, )):
        log_data["message"] = "Skipping task: Task is already active"
        current_app.logger.debug(log_data)
        return
    sync([source])
    log_data["message"] = "Done syncing source"
    current_app.logger.debug(log_data)
示例#3
0
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])
示例#4
0
文件: celery.py 项目: intgr/lemur
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])
示例#5
0
def sync_source(source):
    """
    This celery task will sync the specified source.

    :param source:
    :return:
    """

    function = f"{__name__}.{sys._getframe().f_code.co_name}"
    task_id = None
    if celery.current_task:
        task_id = celery.current_task.request.id

    log_data = {
        "function": function,
        "message": "Syncing source",
        "source": source,
        "task_id": task_id,
    }

    if task_id and is_task_active(function, task_id, (source, )):
        log_data["message"] = "Skipping task: Task is already active"
        current_app.logger.debug(log_data)
        return

    current_app.logger.debug(log_data)
    try:
        sync([source],
             current_app.config.get("CELERY_ENDPOINTS_EXPIRE_TIME_IN_HOURS",
                                    2))
        metrics.send(f"{function}.success",
                     "counter",
                     1,
                     metric_tags={"source": source})
    except SoftTimeLimitExceeded:
        log_data["message"] = "Error syncing source: Time limit exceeded."
        current_app.logger.error(log_data)
        capture_exception()
        metrics.send("sync_source_timeout",
                     "counter",
                     1,
                     metric_tags={"source": source})
        metrics.send("celery.timeout",
                     "counter",
                     1,
                     metric_tags={"function": function})
        return

    log_data["message"] = "Done syncing source"
    current_app.logger.debug(log_data)
    metrics.send(f"{function}.success",
                 "counter",
                 1,
                 metric_tags={"source": source})
    return log_data
示例#6
0
def sync_source(source):
    """
    This celery task will sync the specified source.

    :param source:
    :return:
    """

    function = f"{__name__}.{sys._getframe().f_code.co_name}"
    task_id = None
    if celery.current_task:
        task_id = celery.current_task.request.id
    log_data = {
        "function": function,
        "message": "Syncing source",
        "source": source,
        "task_id": task_id,
    }
    current_app.logger.debug(log_data)

    if task_id and is_task_active(function, task_id, (source, )):
        log_data["message"] = "Skipping task: Task is already active"
        current_app.logger.debug(log_data)
        return
    try:
        sync([source])
        metrics.send(f"{function}.success",
                     'counter',
                     '1',
                     metric_tags={"source": source})
    except SoftTimeLimitExceeded:
        log_data["message"] = "Error syncing source: Time limit exceeded."
        current_app.logger.error(log_data)
        sentry.captureException()
        metrics.send("sync_source_timeout",
                     "counter",
                     1,
                     metric_tags={"source": source})
        return

    log_data["message"] = "Done syncing source"
    current_app.logger.debug(log_data)
    metrics.send(f"{function}.success",
                 'counter',
                 1,
                 metric_tags={"source": source})
    red.set(f'{function}.last_success', int(time.time()))