Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.client.cookies['csrftoken']},
files={'course-data':
(ifname,
test_fp,
"application/x-compressed")})
if resp.status_code != 200:
raise Exception('Course import failed.')
for _ in xrange(100):
resp = self.client.get("/import_status/{0}/{1}".format(cid,
ifname),
name="/import_status/")
if resp.text.find("4") >= 0 or resp.text.find("0") >= 0:
break
time.sleep(0.1)
if resp.text.find("4") >= 0:
events.request_success.fire(request_type="http",
name="course_import",
response_time=(time.time() - start_time) * 1000,
response_length=0)
else:
events.request_failure.fire(request_type="http",
name="course_import",
response_time=(time.time() - start_time) * 1000)
)
request = prediction_pb2.SeldonMessage(data = datadef)
start_time = time.time()
try:
if self.oauth_enabled:
metadata = [('oauth_token', self.access_token)]
response = self.stub.Predict(request=request,metadata=metadata)
else:
response = self.stub.Predict(request=request)
except Exception as e:
total_time = int((time.time() - start_time) * 1000)
print(e)
events.request_failure.fire(request_type="grpc", name=HOST, response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="grpc", name=HOST, response_time=total_time, response_length=0)
events.request_failure.fire(request_type="REPEATED_GET",
name="stopWorkspace_"+self.clusterName,
response_time=self._tick_timer(),
exception="Workspace wasn't able to stop in "
+ str(elapsed_time)
+ " seconds.")
self.log("Workspace " + self.id + " wasn't able to stop in "
+ str(elapsed_time) + " seconds.")
os.system(self.hard_stop_failure_cmd+" -o 1 >/dev/null 2>&1")
return
self.log("Workspace id " + id + " is still not in state STOPPED ["
+ workspace_status +"] {" + str(elapsed_time) + " of " + str(timeout_in_seconds) + "}")
self.wait()
workspace_status = self.getWorkspaceStatus(id)
self.log("Workspace id " + id + " is STOPPED")
events.request_success.fire(request_type="REPEATED_GET",
name="stopWorkspace_"+self.clusterName,
response_time=self._tick_timer(),
response_length=0)
if (isSoftFailure == False):
os.system(self.soft_stop_failure_cmd+" -o 0 >/dev/null 2>&1")
os.system(self.hard_stop_failure_cmd+" -o 0 >/dev/null 2>&1")
def notify_changed(data):
request_success.fire(
request_type='WS',
name='/notifications/connect',
response_time=0,
response_length=0,
)
previous_frame = inspect.currentframe().f_back
(filename, line_number, function_name, lines, index) = inspect.getframeinfo(previous_frame)
topic = args[1]
request_name = f"{func.__name__} {topic}"
start_time = time.time()
result = None
try:
result = func(*args, **kwargs)
except Exception as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="CUSTOM", name=request_name,
response_time=total_time, exception=e, tag=function_name)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="CUSTOM", name=request_name,
response_time=total_time, response_length=0, tag=function_name)
return result
def success(self):
"""
Report the response as successful
Example::
with self.client.get("/does/not/exist", catch_response=True) as response:
if response.status_code == 404:
response.success()
"""
events.request_success.fire(
request_type=self.locust_request_meta["method"],
name=self.locust_request_meta["name"],
response_time=self.locust_request_meta["response_time"],
response_length=self.locust_request_meta["content_size"],
)
self._is_reported = True
def wrapper(*args, **kwargs):
start_time = time.time()
try:
result = func(*args, **kwargs)
except xmlrpclib.Fault as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="xmlrpc", name=name, response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="xmlrpc", name=name, response_time=total_time, response_length=0)
# In this example, I've hardcoded response_length=0. If we would want the response length to be
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(
request_type=request_type,
name=name,
response_time=total_time,
exception=err
)
raise
else:
total_time = int((time.time() - start_time) * 1000)
if isinstance(response, dict): # jsonrpc
size = len(json.dumps(response))
else: # http
response = response.read()
size = len(response)
events.request_success.fire(
request_type=request_type,
name=name,
response_time=total_time,
response_length=size
)
return response
return _wrapper