Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif op.path == "/output":
operation.kwargs["output"] = op.value
elif op.path == "/error_class":
operation.kwargs["error_class"] = op.value
else:
raise ModelValidationError(f"Unsupported operation '{op.operation}'")
response = await self.client(operation)
self.set_header("Content-Type", "application/json; charset=UTF-8")
self.write(response)
class RequestListAPI(BaseHandler):
parser = SchemaParser()
@authenticated(permissions=[Permissions.REQUEST_READ])
async def get(self):
"""
---
summary: Retrieve a page of all Requests
description: |
This endpoint queries multiple requests at once. Because it's intended to be
used with Datatables the query parameters are ... complicated. Here are
things to keep in mind:
* With no query parameters this endpoint will return the first 100 non-child
requests. This can be controlled by passing the `start` and `length` query
parameters.
* This endpoint does NOT return child request definitions. If you want to see
$ref: '#/definitions/Job'
responses:
201:
description: A new job has been created
schema:
$ref: '#/definitions/Job'
400:
$ref: '#/definitions/400Error'
50x:
$ref: '#/definitions/50xError'
tags:
- Jobs
"""
response = await self.client(
brewtils_obj=SchemaParser.parse_job(
self.request.decoded_body, from_string=True
),
route_class=Route_Class.JOB,
route_type=Route_Type.CREATE,
)
self.set_status(201)
self.set_header("Content-Type", "application/json; charset=UTF-8")
self.write(response)
# -*- coding: utf-8 -*-
import asyncio
import json
from concurrent.futures.thread import ThreadPoolExecutor
from functools import partial
import six
from brewtils.models import BaseModel
from brewtils.schema_parser import SchemaParser
import beer_garden.api
class ExecutorClient(object):
parser = SchemaParser()
pool = ThreadPoolExecutor(50)
async def __call__(self, *args, serialize_kwargs=None, **kwargs):
import beer_garden.router
result = await asyncio.get_event_loop().run_in_executor(
self.pool, partial(beer_garden.router.route, *args, **kwargs)
)
# Handlers overwhelmingly just write the response so default to serializing
serialize_kwargs = serialize_kwargs or {}
if "to_string" not in serialize_kwargs:
serialize_kwargs["to_string"] = True
# We're not going to ever double-serialize a string
if isinstance(result, six.string_types):
return result
description: A new System has been created
schema:
$ref: '#/definitions/System'
400:
$ref: '#/definitions/400Error'
50x:
$ref: '#/definitions/50xError'
tags:
- Systems
"""
response = await self.client(
Operation(
operation_type="SYSTEM_CREATE",
args=[
SchemaParser.parse_system(
self.request.decoded_body, from_string=True
)
],
)
)
self.set_status(201)
self.set_header("Content-Type", "application/json; charset=UTF-8")
self.write(response)
:return:None
"""
self.logger.info("Clearing Queue: %s", queue_name)
queue_dictionary = self._client.get_queue(self._virtual_host, queue_name)
number_of_messages = queue_dictionary.get("messages_ready", 0)
while number_of_messages > 0:
self.logger.debug("Getting the Next Message")
messages = self._client.get_messages(
self._virtual_host, queue_name, count=1, requeue=False
)
if messages and len(messages) > 0:
message = messages[0]
try:
request = SchemaParser.parse_request(
message["payload"], from_string=True
)
cancel_request(request)
except Exception as ex:
self.logger.exception(f"Error canceling message: {ex}")
else:
self.logger.debug(
"Race condition: The while loop thought there were more messages "
"to ingest but no more messages could be received."
)
break
number_of_messages -= 1