Esempio n. 1
0
File: orm.py Progetto: kcns008/maas
def make_deadlock_failure():
    """Make a deadlock exception.

    Artificially construct an exception that resembles what Django's ORM would
    raise when PostgreSQL fails a transaction because of a deadlock
    failure.

    :returns: an instance of :py:class:`OperationalError` that will pass the
        `is_deadlock_failure` predicate.
    """
    exception = OperationalError()
    exception.__cause__ = DeadlockFailure()
    assert is_deadlock_failure(exception)
    return exception
Esempio n. 2
0
def save_api(request):
    """ 保存接口调试内容"""
    api_id = request.GET['api_id']
    api_name = request.GET['debug_api_name']
    debug_api_body_method = request.GET['debug_body_method']
    debug_url = request.GET['debug_url']
    debug_host = request.GET['debug_host']
    debug_header = request.GET['debug_header']
    debug_method = request.GET['debug_method']
    debug_api_body = request.GET['debug_api_body']
    if debug_api_body_method == '返回体':
        api = Apis.objects.filter(id=api_id)[0]
        debug_api_body_method = api.last_body_method
        debug_api_body = api.last_api_body
    else:
        debug_api_body = request.GET['debug_api_body']
    # TODO: 需补充接口请求信息内容校验
    # 保存数据
    try:
        Apis.objects.filter(id=api_id).update(
            api_name=api_name,
            api_method=debug_method,
            api_body_method=debug_api_body_method,  # 请求体编码方式
            api_host=debug_host,
            api_url=debug_url,
            api_header=debug_header,
            api_body=debug_api_body,
        )
    except OperationalError:
        raise OperationalError('保存调试信息失败')
    finally:
        return HttpResponse('success')
Esempio n. 3
0
    def ready(self):
        from molo.core.models import Site, CmsSettings

        logging.basicConfig()
        logger = logging.getLogger(__name__)

        try:
            site = Site.objects.first()
            if not site:
                raise OperationalError("No site object")
            timezone = CmsSettings.for_site(site).timezone

            if timezone is None:
                timezone_name = settings.TIME_ZONE
                logger.warning(
                    'Timezone unset, defaulting to {0}'.format(timezone_name))
            else:
                timezone_name = timezone.title

        except (OperationalError, ProgrammingError) as e:
            timezone_name = settings.TIME_ZONE
            logger.warning('Database error: {0}'.format(e))
            logger.warning('Defaulting to timezone: {0}'.format(timezone_name))

        activate(timezone_name)
Esempio n. 4
0
    def handle(self, *args, **options):
        # Sanity check that the database is available and ready --- make sure the system
        # modules exist (since we need them before creating an Organization).
        # Also useful in container deployments to make sure container fully deployed.
        try:
            if not Module.objects.filter(app__source__is_system_source=True,
                                         app__appname="organization",
                                         app__system_app=True,
                                         module_name="app").exists():
                raise OperationalError()  # to trigger below
        except OperationalError:
            print("\n[INFO] - The database is not initialized yet.")
            sys.exit(1)

        # Add default start apps to organizations
        try:
            for org in Organization.objects.all():
                if "default_appversion_name_list" not in org.extra:
                    org.extra["default_appversion_name_list"] = [
                        "Blank Project", "Speedy SSP",
                        "General IT System ATO for 800-53 (low)"
                    ]
                    org.save()
        except:
            print(
                "\n[WARN] Problem adding default project templates to organization. Contact GovReady at [email protected]."
            )

        print("Aspen related configuration upgrades complete.")
Esempio n. 5
0
def check_connection():
    for name in connections:
        with connections[name].cursor() as cursor:
            cursor.execute("SELECT 1;")
            row = cursor.fetchone()
            if row is None:
                raise OperationalError("Invalid response")
Esempio n. 6
0
    def mocked_execute(self, *a, **k):
        counter[0] += 1

        if counter[0] == 1:
            raise OperationalError()
        else:
            return []
Esempio n. 7
0
    def __getitem__(self, model):
        """
        return the data for the given model on the response.
        the data is a dict which for a pk, give back the data representing it.
        :param model: the model to parse the response for
        :return: all the data found in the response corresponding to the model
        :rtype: dict[str|int, dict[str, any]]
        """
        assert isinstance(
            model,
            ModelBase), "you must ask for a django model. not %s" % model
        res = None
        try:
            if model not in self.cache:
                resource_name = get_resource_name(model, many=True)
                pk = model._meta.pk.name

                res = self.cache[model] = collections.OrderedDict(
                    (apidata[pk], apidata)
                    # read all primary request result, and alternative result for the same model,
                    # rendered in a other key prefixed by + (used for foregnkey on self)
                    for apidata in self.json.get(resource_name, []) +
                    self.json.get('+' + resource_name, []))
        except KeyError:
            raise OperationalError(
                "the response from the server does not contains the ID of the model."
            )
        return res or self.cache[model]
Esempio n. 8
0
def resolve_cname(hostname):
    """Resolve a CNAME record to the original RDS endpoint.

    This is required for AWS where the hostname of the RDS instance is part of
    the signing request.

    Looking for the endpoint which is of the form cluster-name.accountandregionhash.regionid.rds.amazonaws.com
    To do so, recursively resolve the host name until it's a subdomain of rds.amazonaws.com.
    """
    base_domain = dns.name.from_text("rds.amazonaws.com")
    answer = dns.name.from_text(hostname)
    while not answer.is_subdomain(base_domain):
        try:
            # Replace deprecated `query` with `resolve`
            # There is one and only one answer for a CNAME and its type is CNAME.
            # If the name doesn't exist or exists with a different type, an exception is raised.
            answer = dns.resolver.resolve(answer,
                                          dns.rdatatype.CNAME,
                                          search=True)[0].target
        except DNSException as e:
            # Break when resolution doesn't work.
            # This avoids cryptic authentication failures from RDS.
            raise OperationalError(
                "Failed to resolve hostname to RDS endpoint.") from e

    return answer.to_text().strip(".")
Esempio n. 9
0
def try4times(func, *arg, **kwarg):
    """
    Work around problems with sqlite3 database getting locked out from writing,
    presumably due to read activity.  Not completely understood.

    This function will try to run func(*arg, **kwarg) a total of 4 times with an
    increasing sequence of wait times between tries.  It catches only a database
    locked error.
    """
    from django.db.utils import OperationalError

    for delay in 0, 5, 10, 60:
        if delay > 0:
            time.sleep(delay)

        try:
            func(*arg, **kwarg)
        except OperationalError as err:
            if 'database is locked' in str(err):
                # Locked DB, issue informational warning
                logger.info(
                    'Warning: locked database, waiting {} seconds'.format(
                        delay))
            else:
                # Something else so just re-raise
                raise
        else:
            # Success, jump out of loop
            break

    else:
        # After 4 tries bail out with an exception
        raise OperationalError('database is locked')
Esempio n. 10
0
class StreamManagerTestCase(TestCase):
    """
    Class for StreamManager test cases.
    """
    fixtures = get_fixtures(['streams'])

    def test_close_all(self):
        """
        Tests the close_all method.
        """
        stream = Stream.objects.get(pk=2)
        assert stream.active
        Stream.objects.close_all()
        stream = Stream.objects.get(pk=2)
        self.assertFalse(stream.active)

    @patch('aggregator.streams.models.Stream.objects.update',
           side_effect=OperationalError('foobar'))
    def test_close_all_exception(self, mock_update):
        """
        Tests the close_all method when an OperationalError is raised.
        """
        with LogCapture() as log_capture:
            Stream.objects.close_all()
            log_capture.check(
                ('aggregator.streams.models',
                 'ERROR',
                 'An error occurred while closing Streams: foobar'),
            )
Esempio n. 11
0
    def test_db_connection_interface_error(self, mock_reset_db,
                                           mock_get_or_create):
        """
        Test that if an InterfaceError or OperationalError is raised,
        Handler._reset_db_connection() is called
        """
        class MockException(Exception):
            pass

        mock_get_or_create.side_effect = [
            InterfaceError(),
            OperationalError(),
            MockException()
        ]

        loop = asyncio.get_event_loop()
        with self.settings(CONTENT_APP_TTL=1):
            try:
                loop.run_until_complete(_heartbeat())
            except MockException:
                pass
        loop.close()

        mock_get_or_create.assert_called()
        mock_reset_db.assert_has_calls([call(), call()])
Esempio n. 12
0
    def test_check_database_is_migrated(self):
        from morango.models import InstanceIDModel

        with patch.object(
            InstanceIDModel, "get_or_create_current_instance"
        ) as get_or_create_current_instance:
            get_or_create_current_instance.side_effect = OperationalError("Test")
            with self.assertRaises(DatabaseNotMigrated):
                sanity_checks.check_database_is_migrated()
Esempio n. 13
0
    def test_limit_reached_mocked(self, mock_max_params):
        mock_max_params.return_value = 1

        test_list = self.pk_list[:2]

        with patch.object(QuerySet, 'count') as mock_method:
            mock_method.side_effect = (OperationalError(), None)
            qs = filter_qs_by_pk_list(Delivery.objects.all(), test_list)
            self.assertEqual(len(qs), 1)
Esempio n. 14
0
    def test_filtering_with_range_convertion_single_item(
            self, mock_max_params):
        mock_max_params.return_value = 1

        with patch.object(QuerySet, 'count') as mock_method:
            mock_method.side_effect = (OperationalError(), None)
            result_qs = filter_qs_by_pk_list(Delivery.objects.all(),
                                             self.pk_list)
            assert list(result_qs.values_list(
                'pk', flat=True)) == [5]  # First item of longest range
Esempio n. 15
0
    def test_filtering_with_range_convertion_split_range(
            self, mock_max_params):
        mock_max_params.return_value = 4

        with patch.object(QuerySet, 'count') as mock_method:
            mock_method.side_effect = (OperationalError(), None)
            result_qs = filter_qs_by_pk_list(Delivery.objects.all(),
                                             self.pk_list)
            assert set(result_qs.values_list('pk', flat=True)) == set(
                [5, 6, 7, 9, 10])
Esempio n. 16
0
def test_migrate_if_unmigrated(version_updated, _migrate_databases):
    # No matter what, ensure that version_updated returns False
    version_updated.return_value = False
    from morango.models import InstanceIDModel

    with patch.object(InstanceIDModel, "get_or_create_current_instance"
                      ) as get_or_create_current_instance:
        get_or_create_current_instance.side_effect = OperationalError("Test")
        cli.initialize()
        _migrate_databases.assert_called_once()
Esempio n. 17
0
 def test_service_status_unhealthy(self, model_manager):
     """
     Test that triggers an exception when the query is executed
     and ensures service status reported as ERROR
     """
     model_manager.exists.side_effect = OperationalError(
         "connection failure")
     response = self.client.post(reverse("ping"))
     self.assertEqual(response.status_code,
                      status.HTTP_500_INTERNAL_SERVER_ERROR)
     self.assertEqual(response.content.decode("utf-8"), "ERROR")
Esempio n. 18
0
    def test_scale_pre_steps_database_operation_error(self, mock_db, mock_sys_exit):
        """Tests executing scale_pre_steps when a database operation error occurs."""

        # Set up mocks
        mock_db.side_effect = OperationalError()

        # Call method to test
        cmd = PreCommand()
        cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)])

        # Check results
        mock_sys_exit.assert_called_with(PRE_DB_OP_EXIT_CODE)
Esempio n. 19
0
    def search(self, config, start, stop, score_field=None):
        normalized_query = normalize(self.query)

        if isinstance(normalized_query, MatchAll):
            return self.queryset[start:stop]

        elif isinstance(normalized_query, Not) and isinstance(normalized_query.subquery, MatchAll):
            return self.queryset.none()

        if isinstance(normalized_query, Not):
            normalized_query = normalized_query.subquery
            negated = True
        else:
            negated = False

        search_query = self.build_search_query(normalized_query, config=config)  # We build a search query here, for example: "%s MATCH '(hello AND world)'"
        vectors = self.get_search_vectors()
        rank_expression = self._build_rank_expression(vectors, config)

        combined_vector = vectors[0][0]  # We create a combined vector for the search results queryset. We start with the first vector and build from there.
        for vector, boost in vectors[1:]:
            combined_vector = combined_vector._combine(vector, ' ', False)  # We add the subsequent vectors to the combined vector.

        expr = MatchExpression(self.fields or ['title', 'body'], search_query)  # Build the FTS match expression.
        objs = SQLiteFTSIndexEntry.objects.filter(expr).select_related('index_entry')  # Perform the FTS search. We'll get entries in the SQLiteFTSIndexEntry model.

        if self.order_by_relevance:
            objs = objs.order_by(BM25().desc())
        elif not objs.query.order_by:
            # Adds a default ordering to avoid issue #3729.
            queryset = objs.order_by('-pk')
            rank_expression = F('pk')

        from django.db import connection
        from django.db.models.sql.subqueries import InsertQuery
        compiler = InsertQuery(IndexEntry).get_compiler(connection=connection)

        try:
            obj_ids = [obj.index_entry.object_id for obj in objs]  # Get the IDs of the objects that matched. They're stored in the IndexEntry model, so we need to get that first.
        except OperationalError:
            raise OperationalError('The original query was' + compiler.compile(objs.query)[0] + str(compiler.compile(objs.query)[1]))

        if not negated:
            queryset = self.queryset.filter(id__in=obj_ids)  # We need to filter the source queryset to get the objects that matched the search query.
        else:
            queryset = self.queryset.exclude(id__in=obj_ids)  # We exclude the objects that matched the search query from the source queryset, if the query is negated.

        if score_field is not None:
            queryset = queryset.annotate(**{score_field: rank_expression})

        return queryset[start:stop]
Esempio n. 20
0
    def test_filtering_with_range_convertion_inside_range(
            self, mock_max_params):
        mock_max_params.return_value = 5

        with patch.object(QuerySet, 'count') as mock_method:
            mock_method.side_effect = (OperationalError(), None)
            result_qs = filter_qs_by_pk_list(Delivery.objects.all(),
                                             self.pk_list)

            assert len(
                result_qs
            ) == 6  # 2 Ranges (4 params, 5 values) + 1 single values
            assert set([5, 6, 7, 9, 10
                        ]).issubset(set(result_qs.values_list(
                            'pk', flat=True)))  # First 5 items from 2 ranges
Esempio n. 21
0
    def handle(self, *app_labels, **options):
        app_label = options.get("app_label")
        model_name = options.get("model_name")
        concurrently = options.get("concurrently")

        model = apps.get_model(app_label, model_name)
        if not model:
            raise OperationalError(f"Cannot find a model named '{model_name}'")

        if not issubclass(model, PostgresMaterializedViewModel):
            raise NotSupportedError(
                f"Model {model.__name__} is not a `PostgresMaterializedViewModel`"
            )

        model.refresh(concurrently=concurrently)
Esempio n. 22
0
def test_ordering_max_limit_exceeded(fixture_property_number_filter, monkeypatch, max_params, expected_result_list):
    monkeypatch.setenv('USER_DB_MAX_PARAMS', str(max_params), prepend=False)

    assert get_max_params_for_db() == max_params

    class PropertyOrderingFilterSet(PropertyFilterSet):
        prop_age = PropertyOrderingFilter(fields=('prop_age', 'prop_age'))

        class Meta:
            model = OrderingFilterModel
            exclude = ['first_name', 'last_name', 'username', 'age']

    prop_filter_fs = PropertyOrderingFilterSet({'prop_age': 'prop_age'}, queryset=OrderingFilterModel.objects.all())

    with patch.object(QuerySet, 'count') as mock_method:
        mock_method.side_effect = (OperationalError(), None)
        assert list(prop_filter_fs.qs.values_list('id', flat=True)) == expected_result_list
Esempio n. 23
0
    def test_scale_post_steps_database_operation_error(self, mock_env_vars,
                                                       mock_db, mock_sys_exit):
        """Tests executing scale_post_steps when a database operation error occurs."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(
                self.job_exe.exe_num)

        mock_env_vars.side_effect = get_env_vars
        mock_db.side_effect = OperationalError()

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        mock_sys_exit.assert_called_with(ScaleOperationalError().exit_code)
Esempio n. 24
0
    def test_metastore_fails(self, mock_first, mock_task):
        mock_first.side_effect = OperationalError()
        mock_task.return_value.get.return_value = None

        response = self.client.get(reverse('healthcheck'))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, {
            'metastore': {
                'status': 'unhealthy',
            },
            'scheduler': {
                'status': 'healthy',
                'latest_scheduler_heartbeat': self.heartbeat.ts,
            },
            'worker': {
                'status': 'unhealthy',
            },
        })
Esempio n. 25
0
class AppsTestCase(BaseWalkingSettingsTestCase):
    @mock.patch('walking_settings.core.load_settings')
    def test_if_appconfig_call_load_settings(self, load_settings_mock):
        ws_config = apps.get_app_config('walking_settings')
        ws_config.ready()
        expect(load_settings_mock.called).to_be_true()

    @mock.patch('walking_settings.core.load_settings',
                side_effect=OperationalError('foo bar'))
    @mock.patch('walking_settings.apps.logger.warning')
    def test_if_appconfig_call_log_warning(self, logging_mock,
                                           load_settings_mock):
        ws_config = apps.get_app_config('walking_settings')
        ws_config.ready()
        expect(load_settings_mock.called).to_be_true()
        expect(logging_mock.called).to_be_true()
        logging_mock.assert_called_once_with(
            'foo bar. This is normal if you are running makemigrate or \
migrate at first time')
Esempio n. 26
0
def get_resource_name(model, many=False):
    """
    return the name of the resource on the server
    if multi is True, it's the url for the «many» models, so we add a «s».
    the resulotion try first to check the APIMeta resource_name and resource_name_plural. if it don't exists,
    it will guess the value from the model name.(lower)
    :param model: the model
    :param bool many: if true, the url of many results
    :return: the resource name (plural if needed)
    :rtype: str
    """
    try:
        if many:
            return getattr(model.APIMeta, 'resource_name_plural',
                           None) or model.__name__.lower() + 's'
        else:
            return getattr(model.APIMeta, 'resource_name',
                           None) or model.__name__.lower()
    except AttributeError:
        raise OperationalError("the given model %s is not a api model" % model)
Esempio n. 27
0
def test_custom_exception_handler_operational_error(mocker):
    """Operation error are translated to service unavailable"""
    fake_exception = OperationalError("Fake internal error", 503)

    response = custom_exception_handler(fake_exception, {})

    assert response is not None
    assert response.status_code == 503

    status = "Database backend maintenance"
    detail = "Service temporarily unavailable, try again later."
    assert (
        response.content.decode("utf-8")
        == f"""<?xml version="1.0" encoding="utf-8"?>
<sword:error xmlns="http://www.w3.org/2005/Atom"
       xmlns:sword="http://purl.org/net/sword/">
    <summary>{status}</summary>
    <sword:verboseDescription>{detail}</sword:verboseDescription>
</sword:error>
"""
    )
Esempio n. 28
0
    def __init__(self):
        super().__init__()

        self.fastsquat_api_endpoint = os.getenv("FASTSQUAT_API_ENDPOINT")
        self.fastsquat_api_token = os.getenv("FASTSQUAT_API_TOKEN")
        if self.fastsquat_api_endpoint is None or self.fastsquat_api_token is None:
            raise OperationalError("Missing FastSquat environment variables.")

        parser = argparse.ArgumentParser()
        parser.add_argument(
            "package",
            help="Package URL to check for typo-squatting.",
            type=str,
        )
        args = parser.parse_args()

        try:
            self.purl = PackageURL.from_string(args.package)
            if self.purl.type == "github":
                raise ValueError(
                    "This job cannot operate on GitHub repositories.")
        except ValueError:
            logger.warning("Invalid PackageURL: %s", args.package)
            raise
Esempio n. 29
0
    def handle(self, *args, **options):
        # Sanity check that the database is available and ready --- make sure the system
        # modules exist (since we need them before creating an Organization).
        # Also useful in container deployments to make sure container fully deployed.
        try:
            if not Module.objects.filter(app__source__is_system_source=True,
                                         app__appname="organization",
                                         app__system_app=True,
                                         module_name="app").exists():
                raise OperationalError()  # to trigger below
        except OperationalError:
            print("The database is not initialized yet.")
            sys.exit(1)

        # Create AppSources that we want.
        if os.path.exists("/mnt/q-files-host"):
            # For our docker image.
            AppSource.objects.get_or_create(slug="host",
                                            defaults={
                                                "spec": {
                                                    "type": "local",
                                                    "path": "/mnt/q-files-host"
                                                }
                                            })
        # Second, for 0.9.x startpack
        # We can use forward slashes because we are storing the path in the database
        # and the path will be applied correctly to the operating OS.
        qfiles_path = 'q-files/vendors/govready/govready-q-files-startpack/q-files'
        if os.path.exists(qfiles_path):
            # For 0.9.x+.
            AppSource.objects.get_or_create(
                slug="govready-q-files-startpack",
                defaults={"spec": {
                    "type": "local",
                    "path": qfiles_path
                }})
            # Load the AppSource's assessments (apps) we want
            # We will do some hard-coding here temporarily
            created_appsource = AppSource.objects.get(
                slug="govready-q-files-startpack")
            for appname in [
                    "System-Description-Demo", "PTA-Demo", "rules-of-behavior",
                    "lightweight-ato"
            ]:
                print("Adding appname '{}' from AppSource '{}' to catalog.".
                      format(appname, created_appsource))
                try:
                    appver = created_appsource.add_app_to_catalog(appname)
                except Exception as e:
                    raise

        # Finally, for authoring, create an AppSource to the stub file
        qfiles_path = 'guidedmodules/stubs/q-files'
        if os.path.exists(qfiles_path):
            # For 0.9.x+.
            AppSource.objects.get_or_create(
                slug="govready-q-files-stubs",
                defaults={"spec": {
                    "type": "local",
                    "path": qfiles_path
                }})
            print("Adding AppSource for authoring.")

        # Create GovReady admin users, if specified in local/environment.json
        if len(settings.GOVREADY_ADMINS):
            for admin_user in settings.GOVREADY_ADMINS:
                username = admin_user["username"]
                if not User.objects.filter(username=username).exists():
                    user = User.objects.create(username=username,
                                               is_superuser=True,
                                               is_staff=True)
                    user.set_password(admin_user["password"])
                    user.email = admin_user["email"]
                    user.save()
                    print(
                        "Created administrator account: username '{}' with email '{}'."
                        .format(user.username, user.email))
                else:
                    print(
                        "\n[WARNING] Skipping create admin account '{}' - username already exists.\n"
                        .format(username))

        # Create the first user.
        if not User.objects.filter(is_superuser=True).exists():
            if not options['non_interactive']:
                print(
                    "Let's create your first Q user. This user will have superuser privileges in the Q administrative interface."
                )
                call_command('createsuperuser')
            else:
                # Create an "admin" account with a random pwd and
                # print it on stdout.
                user = User.objects.create(username="******",
                                           is_superuser=True,
                                           is_staff=True)
                password = User.objects.make_random_password(length=24)
                user.set_password(password)
                user.save()
                print(
                    "Created administrator account (username: {}) with password: {}"
                    .format(user.username, password))
            # Get the admin user - it was just created and should be the only admin user.
            user = User.objects.filter(is_superuser=True).get()

            # Create the first portfolio
            portfolio = Portfolio.objects.create(title=user.username)
            portfolio.assign_owner_permissions(user)
            print("Created administrator portfolio {}".format(portfolio.title))
        else:
            # One or more superusers already exist
            print(
                "\n[WARNING] Superuser(s) already exist, not creating default admin superuser. Did you specify 'govready_admins' in 'local/environment.json'? Are you connecting to a persistent database?\n"
            )

        # Create the default organization.
        if not Organization.objects.all().exists(
        ) and not Organization.objects.filter(name="main").exists():
            org, result = Organization.objects.get_or_create(name="main",
                                                             slug="main")

        # Add the user to the org's help squad and reviewers lists.
        try:
            user
        except NameError:
            print("[WARNING] Admin already added to Help Squad and Reviewers")
        else:
            if user not in org.help_squad.all(): org.help_squad.add(user)
            if user not in org.reviewers.all(): org.reviewers.add(user)

        # Provide feedback to user
        print("GovReady-Q configuration complete.")
Esempio n. 30
0
    def on_message(self, channel: pika.channel.Channel,
                   method_frame: pika.frame.Method,
                   properties: pika.BasicProperties, body: bytes) -> None:
        """
        The process that takes a single message from RabbitMQ, converts it into a python executable and runs it,
        logging the output back to the associated :class:`carrot.models.MessageLog`

        """
        self.channel.basic_ack(method_frame.delivery_tag)
        log = self.__get_message_log(properties, body)
        if log:
            self.active_message_log = log
            log.status = 'IN_PROGRESS'
            log.save()
        else:
            self.logger.error(
                'Unable to find a MessageLog matching the uuid %s. Ignoring this task'
                % properties.message_id)
            return

        try:
            task_type = self.get_task_type(properties.headers, body)
        except KeyError as err:
            return self.fail(
                log,
                'Unable to identify the task type because a key was not found in the message header: %s'
                % err)

        self.logger.info('Consuming task %s, ID=%s' %
                         (task_type, properties.message_id))

        try:
            func = func = self.serializer.get_task(properties, body)
        except (ValueError, ImportError, AttributeError) as err:
            return self.fail(log, err)

        try:
            args, kwargs = self.serializer.serialize_arguments(body.decode())

        except Exception as err:
            return self.fail(
                log,
                'Unable to process the message due to an error collecting the task arguments: %s'
                % err)

        start_msg = '{} {} INFO:: Starting task {}.{}'.format(
            self.name,
            timezone.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3],
            func.__module__, func.__name__)
        self.logger.info(start_msg)
        self.task_log = [start_msg]
        task = LoggingTask(func, self.logger, self.name, *args, **kwargs)

        try:
            output = task.run()

            task_logs = task.get_logs()
            if task_logs:
                self.task_log.append(task_logs)
                self.logger.info(task_logs)

            success = '{} {} INFO:: Task {} completed successfully with response {}'.format(
                self.name,
                timezone.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3], log.task,
                output)
            self.logger.info(success)
            self.task_log.append(success)

            log.status = 'COMPLETED'
            log.completion_time = timezone.now()

            if isinstance(output, dict):
                log.output = json.dumps(output)
            else:
                log.output = output

            log.log = '\n'.join(self.task_log)

            save_attempts = 0

            while True:
                save_attempts += 1

                try:
                    log.save()
                    self.active_message_log = None

                    break
                except OperationalError:
                    if save_attempts > 10:
                        raise OperationalError(
                            'Unable to access the database. This is probably because the number '
                            'of carrot threads is too high. Either reduce the amount of '
                            'scheduled tasks consumers, or increase the max number of '
                            'connections supported by your database')
                    self.connection.sleep(10)

        except Exception as err:
            task_logs = task.get_logs()
            if task_logs:
                self.task_log.append(task_logs)
            self.fail(log, str(err))