@webapi_login_required
    @webapi_check_local_site
    @webapi_response_errors(DOES_NOT_EXIST, NOT_LOGGED_IN, PERMISSION_DENIED)
    @webapi_request_fields(
        required={
            'review_request_id': {
                'type': int,
                'description': 'The ID of the review request.',
            },
            'diff_revision': {
                'type': int,
                'description': 'The diff revision of the review request.',
            },
            'profile_id': {
                'type': int,
                'description': 'The ID of the tool profile to execute.',
            },
        },
    )
    def create(self, request, review_request_id, diff_revision, profile_id,
               *args, **kwargs):
        """Creates a new tool execution, and adds it to the message queue.

        The tool execution will be created only if there are no previous
        executions of the given profile, or if all previous executions failed
        or timed out.

        After this, an execution request (containing the tool execution ID,
        tool profile ID, review request ID, and diff revision) will be added to
        the message queue.
        """
        # Check that the review request, diff revision, and profile all exist.
        try:
            review_request = resources.review_request.get_object(
                request, review_request_id=review_request_id, *args, **kwargs)
        except __HOLE__:
            return DOES_NOT_EXIST

        if not _diff_revision_exists(review_request, diff_revision):
            return DOES_NOT_EXIST

        try:
            profile = Profile.objects.get(pk=profile_id)
        except ObjectDoesNotExist:
            return DOES_NOT_EXIST

        if not self.has_create_permissions(request, review_request, profile):
            return self._no_access_error(request.user)

        # Check that there isn't already a queued/running/succeeded tool
        # execution. We only allow a re-try if previous tool executions failed
        # or timed-out.
        execution_exists = self.model.objects.filter(
            Q(status='Q') | Q(status='R') | Q(status='S'),
            profile=profile,
            review_request_id=review_request_id,
            diff_revision=diff_revision).exists()

        if execution_exists:
            return 409, {}

        tool_execution = self.model.objects.create(
            profile=profile,
            review_request_id=review_request_id,
            diff_revision=diff_revision,
            status='Q')
        tool_execution.save()

        from reviewbotext.extension import ReviewBotExtension
        extension = EXTENSION_MANAGER.get_enabled_extension(
            ReviewBotExtension.id)

        # Add the tool execution request to the message queue.
        request_payload = {
            'tool_execution_id': tool_execution.id,
            'tool_profile_id': profile_id,
            'review_request_id': review_request_id,
            'diff_revision': diff_revision,
        }

        extension.notify(request_payload)

        return 201, {
            self.item_result_key: tool_execution,
        }
dataset/ETHPy150Open reviewboard/ReviewBot/extension/reviewbotext/resources.py/ToolExecutionResource.create