Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine-api
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
Container Registry
Model registry
Operate
Environments
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
AURA
engine-api
Commits
38590ddd
Commit
38590ddd
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Gracefull handle duplicate playlog entries.
parent
798f8cd3
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
src/service.py
+8
-5
8 additions, 5 deletions
src/service.py
src/sync.py
+10
-7
10 additions, 7 deletions
src/sync.py
with
18 additions
and
12 deletions
src/service.py
+
8
−
5
View file @
38590ddd
...
@@ -147,9 +147,12 @@ class ApiService():
...
@@ -147,9 +147,12 @@ class ApiService():
if
self
.
node_type
==
NodeType
.
MAIN
or
\
if
self
.
node_type
==
NodeType
.
MAIN
or
\
(
self
.
node_type
==
NodeType
.
SYNC
and
data
.
log_source
==
self
.
active_source
):
(
self
.
node_type
==
NodeType
.
SYNC
and
data
.
log_source
==
self
.
active_source
):
playlog
=
PlayLog
(
data
)
try
:
playlog
.
save
()
playlog
=
PlayLog
(
data
)
self
.
logger
.
debug
(
"
Stored playlog for
'
%s
'"
%
playlog
.
track_start
)
playlog
.
save
()
self
.
logger
.
debug
(
"
Stored playlog for
'
%s
'"
%
playlog
.
track_start
)
except
sqlalchemy
.
exc
.
IntegrityError
as
e
:
self
.
logger
.
info
(
"
Playlog for
'
%s
'
is already existing in local database. Skipping...
"
%
playlog
.
track_start
)
# Main Node: Push to Sync Node, if enabled
# Main Node: Push to Sync Node, if enabled
if
self
.
node_type
==
NodeType
.
MAIN
and
self
.
sync_host
and
self
.
api_playlog
:
if
self
.
node_type
==
NodeType
.
MAIN
and
self
.
sync_host
and
self
.
api_playlog
:
...
@@ -164,7 +167,7 @@ class ApiService():
...
@@ -164,7 +167,7 @@ class ApiService():
playlog
.
is_synced
=
True
playlog
.
is_synced
=
True
playlog
.
save
()
playlog
.
save
()
else
:
else
:
self
.
logger
.
error
(
"
Error while pushing playlog to sync-node:
"
+
r
.
json
())
self
.
logger
.
error
(
"
Error while pushing playlog to sync-node:
"
+
str
(
r
.
json
())
)
except
Exception
as
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
"
Error while posting to sync-node API
'
%s
'
!
\n
%s
"
%
(
api_url
,
str
(
e
)))
self
.
logger
.
error
(
"
Error while posting to sync-node API
'
%s
'
!
\n
%s
"
%
(
api_url
,
str
(
e
)))
else
:
else
:
...
@@ -253,7 +256,7 @@ class ApiService():
...
@@ -253,7 +256,7 @@ class ApiService():
playlog
.
is_synced
=
True
playlog
.
is_synced
=
True
playlog
.
save
()
playlog
.
save
()
else
:
else
:
self
.
logger
.
error
(
"
Error while pushing healthlog to sync-node:
"
+
r
.
json
())
self
.
logger
.
error
(
"
Error while pushing healthlog to sync-node:
"
+
str
(
r
.
json
())
)
except
Exception
as
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
"
Error while posting to sync-node API
'
%s
'
!
"
%
(
api_url
),
e
)
self
.
logger
.
error
(
"
Error while posting to sync-node API
'
%s
'
!
"
%
(
api_url
),
e
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
src/sync.py
+
10
−
7
View file @
38590ddd
...
@@ -105,13 +105,16 @@ class SyncJob(threading.Thread):
...
@@ -105,13 +105,16 @@ class SyncJob(threading.Thread):
# Store unsynced entries locally
# Store unsynced entries locally
for
entry
in
entries
:
for
entry
in
entries
:
playlog
=
PlayLog
(
entry
)
self
.
Session
.
add
(
playlog
)
self
.
Session
.
commit
()
self
.
logger
.
info
(
"
Stored synced playlog for
'
%s
'"
%
playlog
.
track_start
)
try
:
synced_entries
+=
1
playlog
=
PlayLog
(
entry
)
self
.
Session
.
add
(
playlog
)
self
.
Session
.
commit
()
self
.
logger
.
info
(
"
Stored synced playlog for
'
%s
'"
%
playlog
.
track_start
)
synced_entries
+=
1
except
sqlalchemy
.
exc
.
IntegrityError
as
e
:
self
.
logger
.
info
(
"
Playlog for
'
%s
'
is already existing in local database. Skipping...
"
%
playlog
.
track_start
)
# Sleep a little to keep the effective load down low
# Sleep a little to keep the effective load down low
time
.
sleep
(
self
.
config
.
get
(
"
sync_step_sleep
"
))
time
.
sleep
(
self
.
config
.
get
(
"
sync_step_sleep
"
))
...
@@ -152,7 +155,7 @@ class SyncJob(threading.Thread):
...
@@ -152,7 +155,7 @@ class SyncJob(threading.Thread):
to_time
=
next_source
.
log_time
to_time
=
next_source
.
log_time
try
:
try
:
params
=
{
"
page
"
:
"
0
"
,
"
limit
"
:
self
.
sync_batch_size
,
"
skip_synced
"
:
"
true
"
,
"
from
"
:
source
.
log_time
,
"
to
"
:
to_time
}
params
=
{
"
page
"
:
"
0
"
,
"
limit
"
:
self
.
sync_batch_size
,
"
skip_synced
"
:
"
true
"
,
"
from
_date
"
:
source
.
log_time
,
"
to
_date
"
:
to_time
}
url
=
self
.
get_url
(
source
.
source_number
)
url
=
self
.
get_url
(
source
.
source_number
)
response
=
requests
.
get
(
url
,
params
=
params
)
response
=
requests
.
get
(
url
,
params
=
params
)
if
response
.
status_code
==
200
:
if
response
.
status_code
==
200
:
...
...
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