Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
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
Container 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
geant-swd
dashboardv3
inventory-provider
Commits
561b3daf
Commit
561b3daf
authored
5 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
implemented latch method
parent
81672c40
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/routes/jobs.py
+25
-0
25 additions, 0 deletions
inventory_provider/routes/jobs.py
inventory_provider/tasks/common.py
+17
-2
17 additions, 2 deletions
inventory_provider/tasks/common.py
with
42 additions
and
2 deletions
inventory_provider/routes/jobs.py
+
25
−
0
View file @
561b3daf
from
flask
import
Blueprint
,
current_app
,
jsonify
from
inventory_provider.tasks
import
worker
from
inventory_provider.tasks
import
common
as
worker_common
from
inventory_provider.routes
import
common
routes
=
Blueprint
(
"
inventory-data-job-routes
"
,
__name__
)
...
...
@@ -36,3 +37,27 @@ def reload_router_config(equipment_name):
@common.require_accepts_json
def
check_task_status
(
task_id
):
return
jsonify
(
worker
.
check_task_status
(
task_id
))
@routes.route
(
"
latchdb
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
latch_db
():
config
=
current_app
.
config
[
"
INVENTORY_PROVIDER_CONFIG
"
]
db_ids
=
config
[
'
redis-databases
'
]
db_ids
=
sorted
(
set
(
db_ids
))
r
=
worker_common
.
get_next_redis
(
config
)
latch
=
worker_common
.
get_latch
(
r
)
if
not
latch
:
latch
=
{
'
current
'
:
db_ids
[
0
],
'
next
'
:
db_ids
[
0
]
}
next_idx
=
db_ids
.
index
(
latch
[
'
next
'
])
next_idx
=
(
next_idx
+
1
)
%
len
(
db_ids
)
worker_common
.
set_latch
(
config
,
new_current
=
latch
[
'
next
'
],
new_next
=
db_ids
[
next_idx
])
r
=
worker_common
.
get_current_redis
(
config
)
return
jsonify
(
worker_common
.
get_latch
(
r
))
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/common.py
+
17
−
2
View file @
561b3daf
...
...
@@ -35,13 +35,28 @@ def get_latch(r):
return
latch
def
set_latch
(
config
,
new_current
,
new_next
):
for
db
in
config
[
'
redis-databases
'
]:
latch
=
{
'
current
'
:
new_current
,
'
next
'
:
new_next
,
'
this
'
:
db
}
r
=
_get_redis
(
config
,
dbid
=
db
)
r
.
set
(
'
db:latch
'
,
json
.
dumps
(
latch
))
def
_get_redis
(
config
,
dbid
=
None
):
if
dbid
is
None
:
logger
.
debug
(
'
no db specified, using minimum as first guess
'
)
dbid
=
min
(
config
[
'
redis-databases
'
])
assert
dbid
in
config
[
'
redis-databases
'
]
if
dbid
not
in
config
[
'
redis-databases
'
]:
logger
.
error
(
'
tried to connect to unknown db id: {}
'
.
format
(
dbid
))
dbid
=
min
(
config
[
'
redis-databases
'
])
kwargs
=
{
'
db
'
:
dbid
,
...
...
@@ -81,7 +96,7 @@ def get_next_redis(config):
if
latch
and
latch
[
'
this
'
]
==
latch
[
'
next
'
]:
return
r
if
latch
:
if
latch
and
latch
[
'
next
'
]
in
config
[
'
redis-databases
'
]
:
next_id
=
latch
[
'
next
'
]
else
:
logger
.
warning
(
"
next db not configured, deriving default value
"
)
...
...
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