Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
a4782c83
Commit
a4782c83
authored
7 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
Task #10902: use local cache for task status/type and claim status
parent
89df86ed
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py
+24
-12
24 additions, 12 deletions
SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py
with
24 additions
and
12 deletions
SAS/ResourceAssignment/ResourceAssignmentDatabase/radb.py
+
24
−
12
View file @
a4782c83
...
...
@@ -45,8 +45,10 @@ class RADatabase:
self
.
conn
=
None
self
.
cursor
=
None
self
.
log_queries
=
log_queries
self
.
_taskStatusCache
=
{}
self
.
_taskTypeCache
=
{}
self
.
_taskStatusName2IdCache
=
{}
self
.
_taskTypeName2IdCache
=
{}
self
.
_claimStatusName2IdCache
=
{}
self
.
_claimStatusId2NameCache
=
{}
def
_connect
(
self
):
self
.
conn
=
None
...
...
@@ -119,16 +121,16 @@ class RADatabase:
def
getTaskStatusNames
(
self
):
return
[
x
[
'
name
'
]
for
x
in
self
.
getTaskStatuses
()]
def
getTaskStatusId
(
self
,
status_name
,
from_cache
=
Fals
e
):
if
from_cache
and
status_name
in
self
.
_taskStatusCache
:
return
self
.
_taskStatusCache
[
status_name
]
def
getTaskStatusId
(
self
,
status_name
,
from_cache
=
Tru
e
):
if
from_cache
and
status_name
in
self
.
_taskStatus
Name2Id
Cache
:
return
self
.
_taskStatus
Name2Id
Cache
[
status_name
]
query
=
'''
SELECT id from resource_allocation.task_status
WHERE name = %s;
'''
result
=
self
.
_executeQuery
(
query
,
[
status_name
],
fetch
=
_FETCH_ONE
)
if
result
:
self
.
_taskStatusCache
[
status_name
]
=
result
[
'
id
'
]
self
.
_taskStatus
Name2Id
Cache
[
status_name
]
=
result
[
'
id
'
]
return
result
[
'
id
'
]
raise
KeyError
(
'
No such status: %s Valid values are: %s
'
%
(
status_name
,
'
,
'
.
join
(
self
.
getTaskStatusNames
())))
...
...
@@ -141,16 +143,16 @@ class RADatabase:
def
getTaskTypeNames
(
self
):
return
[
x
[
'
name
'
]
for
x
in
self
.
getTaskTypes
()]
def
getTaskTypeId
(
self
,
type_name
,
from_cache
=
Fals
e
):
if
from_cache
and
type_name
in
self
.
_task
Status
Cache
:
return
self
.
_taskTypeCache
[
type_name
]
def
getTaskTypeId
(
self
,
type_name
,
from_cache
=
Tru
e
):
if
from_cache
and
type_name
in
self
.
_task
TypeName2Id
Cache
:
return
self
.
_taskType
Name2Id
Cache
[
type_name
]
query
=
'''
SELECT id from resource_allocation.task_type
WHERE name = %s;
'''
result
=
self
.
_executeQuery
(
query
,
[
type_name
],
fetch
=
_FETCH_ONE
)
if
result
:
self
.
_taskTypeCache
[
type_name
]
=
result
[
'
id
'
]
self
.
_taskType
Name2Id
Cache
[
type_name
]
=
result
[
'
id
'
]
return
result
[
'
id
'
]
raise
KeyError
(
'
No such type: %s Valid values are: %s
'
%
(
type_name
,
'
,
'
.
join
(
self
.
getTaskTypeNames
())))
...
...
@@ -163,22 +165,32 @@ class RADatabase:
def
getResourceClaimStatusNames
(
self
):
return
[
x
[
'
name
'
]
for
x
in
self
.
getResourceClaimStatuses
()]
def
getResourceClaimStatusId
(
self
,
status_name
):
def
getResourceClaimStatusId
(
self
,
status_name
,
from_cache
=
True
):
if
from_cache
and
status_name
in
self
.
_claimStatusName2IdCache
:
return
self
.
_claimStatusName2IdCache
[
status_name
]
query
=
'''
SELECT id from resource_allocation.resource_claim_status
WHERE name = %s;
'''
result
=
self
.
_executeQuery
(
query
,
[
status_name
],
fetch
=
_FETCH_ONE
)
if
result
:
self
.
_claimStatusName2IdCache
[
status_name
]
=
result
[
'
id
'
]
self
.
_claimStatusId2NameCache
[
result
[
'
id
'
]]
=
status_name
return
result
[
'
id
'
]
raise
KeyError
(
'
No such status: %s. Valid values are: %s
'
%
(
status_name
,
'
,
'
.
join
(
self
.
getResourceClaimStatusNames
())))
def
getResourceClaimStatusName
(
self
,
status_id
):
def
getResourceClaimStatusName
(
self
,
status_id
,
from_cache
=
True
):
if
from_cache
and
status_id
in
self
.
_claimStatusId2NameCache
:
return
self
.
_claimStatusId2NameCache
[
status_id
]
query
=
'''
SELECT name from resource_allocation.resource_claim_status
WHERE id = %s;
'''
result
=
self
.
_executeQuery
(
query
,
[
status_id
],
fetch
=
_FETCH_ONE
)
if
result
:
self
.
_claimStatusId2NameCache
[
status_id
]
=
result
[
'
name
'
]
self
.
_claimStatusName2IdCache
[
result
[
'
name
'
]]
=
status_id
return
result
[
'
name
'
]
raise
KeyError
(
'
No such status_id: %s. Valid values are: %s
'
%
(
status_id
,
'
,
'
.
join
([
x
[
'
id
'
]
for
x
in
self
.
getResourceClaimStatuses
()])))
...
...
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