Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jussi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
jussi
Commits
4185025d
Unverified
Commit
4185025d
authored
6 years ago
by
John G G
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into timeouts
parents
227d8e24
1b7dccd7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
jussi/errors.py
+3
-26
3 additions, 26 deletions
jussi/errors.py
jussi/ws/pool.py
+1
-12
1 addition, 12 deletions
jussi/ws/pool.py
with
4 additions
and
38 deletions
jussi/errors.py
+
3
−
26
View file @
4185025d
...
...
@@ -17,7 +17,6 @@ from .typedefs import HTTPResponse
from
.typedefs
import
JrpcRequest
from
.typedefs
import
JrpcResponse
from
.typedefs
import
WebApp
from
.async_stats
import
fmt_timings
logger
=
structlog
.
get_logger
(
__name__
)
...
...
@@ -34,6 +33,7 @@ class Default(dict):
def
setup_error_handlers
(
app
:
WebApp
)
->
WebApp
:
# pylint: disable=unused-variable
@app.exception
(
sanic
.
exceptions
.
RequestTimeout
)
def
handle_request_timeout_errors
(
request
:
HTTPRequest
,
exception
:
sanic
.
exceptions
.
RequestTimeout
)
->
Optional
[
HTTPResponse
]:
...
...
@@ -43,6 +43,7 @@ def setup_error_handlers(app: WebApp) -> WebApp:
jrpc_request
=
request
.
jsonrpc
,
exception
=
exception
).
to_sanic_response
()
@app.exception
(
sanic
.
exceptions
.
ServiceUnavailable
)
def
handle_response_timeout_errors
(
request
:
HTTPRequest
,
exception
:
sanic
.
exceptions
.
ServiceUnavailable
)
->
Optional
[
HTTPResponse
]:
...
...
@@ -206,30 +207,6 @@ class JussiInteralError(Exception):
return
base_error
def
timings
(
self
)
->
Optional
[
dict
]:
try
:
if
self
.
http_request
.
is_single_jrpc
:
request_timings
=
fmt_timings
(
self
.
http_request
.
timings
)
jsonrpc_timings
=
fmt_timings
(
self
.
http_request
.
jsonrpc
.
timings
)
return
{
'
request_timings
'
:
request_timings
,
'
jsonrpc_timings
'
:
jsonrpc_timings
}
elif
self
.
http_request
.
is_batch_jrpc
:
request_timings
=
fmt_timings
(
self
.
http_request
.
timings
)
jsonrpc_timings
=
[]
for
r
in
self
.
http_request
.
jsonrpc
:
jsonrpc_timings
.
extend
(
fmt_timings
(
r
.
timings
))
return
{
'
request_timings
'
:
request_timings
,
'
jsonrpc_timings
'
:
jsonrpc_timings
}
else
:
return
None
except
Exception
as
e
:
return
None
def
log
(
self
)
->
None
:
if
self
.
log_traceback
and
self
.
exception
:
self
.
logger
.
error
(
self
.
format_message
(),
**
self
.
to_dict
(),
...
...
@@ -318,7 +295,7 @@ class ResponseTimeoutError(JsonRpcError):
logger
.
info
(
'
error adding timing data to RequestTimeoutError
'
,
e
=
e
)
return
data
class
UpstreamResponseError
(
JsonRpcError
):
code
=
1100
message
=
'
Upstream response error
'
...
...
This diff is collapsed.
Click to expand it.
jussi/ws/pool.py
+
1
−
12
View file @
4185025d
# -*- coding: utf-8 -*-
import
asyncio
from
time
import
perf_counter
import
structlog
# pylint: disable=no-name-in-module
from
websockets
import
WebSocketClientProtocol
as
WSConn
...
...
@@ -266,26 +264,17 @@ class Pool:
async
def
_get_new_connection
(
self
)
->
WSConn
:
# First connection attempt on this pool.
logger
.
debug
(
'
spawning new ws conn
'
)
start
=
perf_counter
()
conn
=
await
websockets_connect
(
self
.
_connect_url
,
loop
=
self
.
_loop
,
return
await
websockets_connect
(
self
.
_connect_url
,
loop
=
self
.
_loop
,
**
self
.
_connect_kwargs
)
elapsed
=
perf_counter
()
-
start
logger
.
info
(
'
new ws conn
'
,
elapsed
=
elapsed
)
return
conn
async
def
acquire
(
self
,
timeout
:
int
=
None
)
->
PoolConnectionProxy
:
async
def
_acquire_impl
(
timeout
=
None
)
->
PoolConnectionProxy
:
start
=
perf_counter
()
ch
=
await
self
.
_queue
.
get
()
# type: PoolConnectionHolder
self
.
_queue
.
task_done
()
try
:
proxy
=
await
ch
.
acquire
()
# type: # type: PoolConnectionProxy
elapsed
=
perf_counter
()
-
start
if
elapsed
>
1
:
logger
.
info
(
'
acquire ws conn
'
,
elapsed
=
elapsed
)
except
Exception
:
self
.
_queue
.
put_nowait
(
ch
)
raise
else
:
# Record the timeout, as we will apply it by default
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment