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
560c784c
Commit
560c784c
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Run sync job in sync mode only.
parent
9099fda7
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/app.py
+14
-3
14 additions, 3 deletions
src/app.py
src/base/node.py
+32
-0
32 additions, 0 deletions
src/base/node.py
src/service.py
+4
-19
4 additions, 19 deletions
src/service.py
src/sync.py
+1
-1
1 addition, 1 deletion
src/sync.py
with
51 additions
and
23 deletions
src/app.py
+
14
−
3
View file @
560c784c
...
@@ -27,6 +27,7 @@ import connexion
...
@@ -27,6 +27,7 @@ import connexion
from
base.config
import
AuraConfig
from
base.config
import
AuraConfig
from
base.logger
import
AuraLogger
from
base.logger
import
AuraLogger
from
base.node
import
NodeType
from
rest
import
encoder
from
rest
import
encoder
from
service
import
ApiService
from
service
import
ApiService
from
sync
import
SyncJob
from
sync
import
SyncJob
...
@@ -76,10 +77,20 @@ with app.app_context():
...
@@ -76,10 +77,20 @@ with app.app_context():
Initialize Server.
Initialize Server.
"""
"""
db
.
create_all
()
db
.
create_all
()
service
=
ApiService
(
config
,
logger
)
# Evaluate deployment mode
node_type
=
NodeType
.
MAIN
if
config
.
get
(
"
host_id
"
)
==
0
:
node_type
=
NodeType
.
SYNC
service
=
ApiService
(
config
,
logger
,
node_type
)
app
.
config
[
'
SERVICE
'
]
=
service
app
.
config
[
'
SERVICE
'
]
=
service
sync_job
=
SyncJob
(
config
,
logger
,
app
)
sync_job
.
start
()
# Run sync job only in SYNC NODE mode
if
node_type
==
NodeType
.
SYNC
:
sync_job
=
SyncJob
(
config
,
logger
,
app
)
sync_job
.
start
()
atexit
.
register
(
shutdown
)
atexit
.
register
(
shutdown
)
logger
.
info
(
"
Engine API server initialized.
"
)
logger
.
info
(
"
Engine API server initialized.
"
)
...
...
This diff is collapsed.
Click to expand it.
src/base/node.py
0 → 100644
+
32
−
0
View file @
560c784c
#
# Aura Engine API (https://gitlab.servus.at/aura/engine-api)
#
# Copyright (C) 2020 - The Aura Engine Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
enum
import
Enum
from
models
import
PlayLog
,
PlayLogSchema
,
TrackSchema
,
ActivityLog
,
HealthHistory
,
HealthHistorySchema
class
NodeType
(
Enum
):
"""
Types of API Server deployment models.
"""
MAIN
=
"
main
"
SYNC
=
"
sync
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/service.py
+
4
−
19
View file @
560c784c
...
@@ -18,22 +18,13 @@
...
@@ -18,22 +18,13 @@
import
datetime
import
datetime
import
requests
from
enum
import
Enum
from
base.node
import
NodeType
from
models
import
PlayLog
,
PlayLogSchema
,
TrackSchema
,
ActivityLog
,
HealthHistory
,
HealthHistorySchema
from
models
import
PlayLog
,
PlayLogSchema
,
TrackSchema
,
ActivityLog
,
HealthHistory
,
HealthHistorySchema
class
NodeType
(
Enum
):
"""
Types of API Server deployment models.
"""
MAIN
=
"
main
"
SYNC
=
"
sync
"
class
ApiService
():
class
ApiService
():
"""
"""
Service handling for API actions.
Service handling for API actions.
...
@@ -49,19 +40,13 @@ class ApiService():
...
@@ -49,19 +40,13 @@ class ApiService():
api_healthlog
=
None
api_healthlog
=
None
def
__init__
(
self
,
config
,
logger
):
def
__init__
(
self
,
config
,
logger
,
node_type
):
"""
"""
Initialize Service.
Initialize Service.
"""
"""
self
.
config
=
config
self
.
config
=
config
self
.
logger
=
logger
self
.
logger
=
logger
# Evaluate deployment mode
node_type
=
NodeType
.
MAIN
host_id
=
config
.
get
(
"
host_id
"
)
if
host_id
==
0
:
node_type
=
NodeType
.
SYNC
# Configured as Sync Node
# Configured as Sync Node
if
not
node_type
==
NodeType
.
MAIN
:
if
not
node_type
==
NodeType
.
MAIN
:
self
.
node_type
=
NodeType
.
SYNC
self
.
node_type
=
NodeType
.
SYNC
...
@@ -181,7 +166,7 @@ class ApiService():
...
@@ -181,7 +166,7 @@ class ApiService():
else
:
else
:
self
.
logger
.
error
(
"
Error while pushing playlog to sync-node:
"
+
r
.
json
())
self
.
logger
.
error
(
"
Error while pushing playlog to sync-node:
"
+
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
'
!
\n
%s
"
%
(
api_url
,
str
(
e
))
)
else
:
else
:
self
.
logger
.
info
(
"
Ditching playlog sent from an inactive source
"
)
self
.
logger
.
info
(
"
Ditching playlog sent from an inactive source
"
)
...
...
This diff is collapsed.
Click to expand it.
src/sync.py
+
1
−
1
View file @
560c784c
...
@@ -161,7 +161,7 @@ class SyncJob(threading.Thread):
...
@@ -161,7 +161,7 @@ class SyncJob(threading.Thread):
else
:
else
:
self
.
logger
.
error
(
"
Invalid status code while getting unsynced entries from remote API:
"
+
str
(
response
.
status_code
))
self
.
logger
.
error
(
"
Invalid status code while getting unsynced entries from remote API:
"
+
str
(
response
.
status_code
))
except
Exception
as
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
"
Error while getting unsynced entries from remote API
'
%s
'
!
"
%
(
url
)
,
e
)
self
.
logger
.
error
(
"
Error while getting unsynced entries from remote API
'
%s
'
!
\n
%s
"
%
(
url
,
str
(
e
))
)
raise
e
raise
e
...
...
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