def create_bucket(minio_client, bucket):
    if not minio_client.bucket_exists(bucket):
        logger.info("Creating bucket {}".format(bucket))
        try:
            minio_client.make_bucket(bucket)
        except minio.error.BucketAlreadyOwnedByYou:
            logger.info("The bucket {} was already created.".format(bucket))
Example #2
0
def calculate_comparison_rate():
    with DBConn() as dbinstance:
        logger.info("Calculating global comparison rate")

        total_comparisons = 0
        total_time = timedelta(0)
        for run in get_elapsed_run_times(dbinstance):

            comparisons = get_total_comparisons_for_project(dbinstance, run['project_id'])

            if comparisons != 'NA':
                total_comparisons += comparisons
            else:
                logger.debug("Skipping run as it hasn't completed")
            total_time += run['elapsed']

        if total_time.total_seconds() > 0:
            rate = total_comparisons/total_time.total_seconds()
            logger.info("Total comparisons: {}".format(total_comparisons))
            logger.info("Total time:        {}".format(total_time.total_seconds()))
            logger.info("Comparison rate:   {:.0f}".format(rate))

            with dbinstance.cursor() as cur:
                insert_comparison_rate(cur, rate)

        else:
            logger.warning("Can't compute comparison rate yet")
def run_failed_handler(*args, **kwargs):
    """
    Record that a task has encountered an error, mark the run as failed.

    :param args: A 1-tuple starting with the result id.
    :param kwargs: Keyword arguments to the task e.g. {'run_id': '...', }
    """
    task_id = args[0]
    if 'run_id' in kwargs:
        logger.bind(run_id=kwargs['run_id'])
    logger.info("An error occurred while processing task", task_id=task_id)

    with DBConn() as db:
        update_run_mark_failure(db, kwargs['run_id'])
    logger.warning("Marked run as failure")
Example #4
0
    def on_failure(self, exc, task_id, args, kwargs, einfo):
        """Log the exceptions"""
        logger.info("An exception '{}' was raised in a task".format(
            exc.__class__.__name__))

        if isinstance(exc, (DBResourceMissing, psycopg2.IntegrityError)):
            logger.info(
                "Task was running when a resource was deleted, or db was inconsistent. Ignoring"
            )
            # Note it will still be logged by celery
            # http://docs.celeryproject.org/en/master/userguide/tasks.html#Task.throws

        else:
            logger.exception(f"Unexpected exception raised in task {task_id}",
                             exc_info=einfo)
            super(BaseTask, self).on_failure(exc, task_id, args, kwargs, einfo)
Example #5
0
def on_chord_error(*args, **kwargs):
    logger.info("An error occurred while processing the chord's tasks")
    with DBConn() as db:
        update_run_mark_failure(db, kwargs['run_id'])
    logger.warning("Marked run as failure")