Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calparrot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
calibration
calparrot
Commits
1765a21c
Commit
1765a21c
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Catch sqlite timeout & forward queries to CalCat
parent
3baadcd5
No related branches found
No related tags found
1 merge request
!3
Catch sqlite timeout & forward queries to CalCat
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
calparrot/proxy.py
+21
-4
21 additions, 4 deletions
calparrot/proxy.py
with
21 additions
and
4 deletions
calparrot/proxy.py
+
21
−
4
View file @
1765a21c
...
@@ -7,6 +7,7 @@ constants.
...
@@ -7,6 +7,7 @@ constants.
import
asyncio
import
asyncio
import
logging
import
logging
import
os
import
os
import
sqlite3
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
secrets
import
token_hex
from
secrets
import
token_hex
from
urllib.parse
import
parse_qs
,
urlencode
from
urllib.parse
import
parse_qs
,
urlencode
...
@@ -140,7 +141,20 @@ class ProxyHandler(RequestHandler):
...
@@ -140,7 +141,20 @@ class ProxyHandler(RequestHandler):
)
)
async
def
_get_with_cache
(
self
,
req_path
)
->
ProxyResponse
:
async
def
_get_with_cache
(
self
,
req_path
)
->
ProxyResponse
:
if
self
.
response_store
.
insert_pending
(
req_path
,
self
.
request
.
body
):
store_response
=
True
try
:
new_query
=
self
.
response_store
.
insert_pending
(
req_path
,
self
.
request
.
body
)
except
sqlite3
.
OperationalError
:
log
.
warning
(
"
Could not check for query (%s) in CalParrot database.
"
"
Will treat this as new & forward to CalCat.
"
,
exc_info
=
True
,
)
new_query
=
True
# Don't try to write the response if there are issues accessing the DB
store_response
=
False
if
new_query
:
if
os
.
environ
.
get
(
'
CALPARROT_NEW_QUERY
'
,
''
).
lower
()
==
'
warn
'
:
if
os
.
environ
.
get
(
'
CALPARROT_NEW_QUERY
'
,
''
).
lower
()
==
'
warn
'
:
log
.
warning
(
log
.
warning
(
"
CalParrot received a new query (for %s) when it was told to
"
"
CalParrot received a new query (for %s) when it was told to
"
...
@@ -150,9 +164,11 @@ class ProxyHandler(RequestHandler):
...
@@ -150,9 +164,11 @@ class ProxyHandler(RequestHandler):
"
New CalCat queries made while reproducing correction
"
"
New CalCat queries made while reproducing correction
"
)
)
#
We put a pending response in the database: now
query upstream
#
Send
query upstream
resp
=
await
self
.
_get_upstream
(
req_path
)
resp
=
await
self
.
_get_upstream
(
req_path
)
self
.
_record_response
(
req_path
,
resp
)
if
store_response
:
# We put a pending record in the database; add the response
self
.
_record_response
(
req_path
,
resp
)
else
:
else
:
# This URL is already in the database
# This URL is already in the database
try
:
try
:
...
@@ -169,7 +185,8 @@ class ProxyHandler(RequestHandler):
...
@@ -169,7 +185,8 @@ class ProxyHandler(RequestHandler):
"
forwarding request for %s
"
,
req_path
"
forwarding request for %s
"
,
req_path
)
)
resp
=
await
self
.
_get_upstream
(
req_path
)
resp
=
await
self
.
_get_upstream
(
req_path
)
self
.
_record_response
(
req_path
,
resp
)
if
store_response
:
self
.
_record_response
(
req_path
,
resp
)
return
resp
return
resp
...
...
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