Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
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
Commits
4b2488ef
Commit
4b2488ef
authored
1 year ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
refactor: extend merge strategy
parent
eb5f7c7b
No related branches found
No related tags found
1 merge request
!35
ORM-less scheduling
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aura_engine/scheduling/timetable.py
+23
-12
23 additions, 12 deletions
src/aura_engine/scheduling/timetable.py
with
23 additions
and
12 deletions
src/aura_engine/scheduling/timetable.py
+
23
−
12
View file @
4b2488ef
...
@@ -37,6 +37,7 @@ import jsonpickle
...
@@ -37,6 +37,7 @@ import jsonpickle
import
aura_engine.engine
as
engine
import
aura_engine.engine
as
engine
import
aura_engine.scheduling.api
as
api
import
aura_engine.scheduling.api
as
api
from
aura_engine.base.config
import
AuraConfig
from
aura_engine.base.config
import
AuraConfig
from
aura_engine.base.lang
import
synchronized
from
aura_engine.base.utils
import
SimpleUtil
as
SU
from
aura_engine.base.utils
import
SimpleUtil
as
SU
from
aura_engine.scheduling.domain
import
Playlist
,
PlaylistItem
,
Timeslot
from
aura_engine.scheduling.domain
import
Playlist
,
PlaylistItem
,
Timeslot
...
@@ -76,6 +77,7 @@ class TimetableService:
...
@@ -76,6 +77,7 @@ class TimetableService:
self
.
timetable_file
=
self
.
cache_location
+
"
/timetable.json
"
self
.
timetable_file
=
self
.
cache_location
+
"
/timetable.json
"
self
.
load_timetable
()
self
.
load_timetable
()
@synchronized
def
refresh
(
self
):
def
refresh
(
self
):
"""
"""
Update the timetable.
Update the timetable.
...
@@ -208,7 +210,7 @@ class TimetableService:
...
@@ -208,7 +210,7 @@ class TimetableService:
return
current_timeslot
return
current_timeslot
def
get_next_timeslots
(
self
,
max_count
:
int
=
0
,
window_aware
=
False
)
->
[
Timeslot
]:
def
get_next_timeslots
(
self
,
max_count
:
int
=
0
,
window_aware
=
False
)
->
list
[
Timeslot
]:
"""
"""
Retrieve the timeslots to be played after the current one.
Retrieve the timeslots to be played after the current one.
...
@@ -356,6 +358,7 @@ class TimetableMerger:
...
@@ -356,6 +358,7 @@ class TimetableMerger:
idx
[
"
local
"
]
=
None
idx
[
"
local
"
]
=
None
return
timeslot_map
return
timeslot_map
@synchronized
def
merge
(
def
merge
(
self
,
local_timeslots
:
list
[
Timeslot
],
remote_timeslots
:
list
[
Timeslot
]
self
,
local_timeslots
:
list
[
Timeslot
],
remote_timeslots
:
list
[
Timeslot
]
)
->
list
[
Timeslot
]:
)
->
list
[
Timeslot
]:
...
@@ -380,8 +383,8 @@ class TimetableMerger:
...
@@ -380,8 +383,8 @@ class TimetableMerger:
merge_info
=
SU
.
cyan
(
"
\n
Map for timetable merge:
"
)
merge_info
=
SU
.
cyan
(
"
\n
Map for timetable merge:
"
)
for
timestamp
,
ts_relation
in
timeslot_map
.
items
():
for
timestamp
,
ts_relation
in
timeslot_map
.
items
():
local
=
ts_relation
.
get
(
"
local
"
)
local
:
Timeslot
=
ts_relation
.
get
(
"
local
"
)
remote
=
ts_relation
.
get
(
"
remote
"
)
remote
:
Timeslot
=
ts_relation
.
get
(
"
remote
"
)
if
(
float
(
timestamp
)
-
scheduling_window_start
)
<
now
:
if
(
float
(
timestamp
)
-
scheduling_window_start
)
<
now
:
# It's past the scheduling window, so keep the local one as is
# It's past the scheduling window, so keep the local one as is
...
@@ -396,21 +399,29 @@ class TimetableMerger:
...
@@ -396,21 +399,29 @@ class TimetableMerger:
if
local
and
not
remote
:
if
local
and
not
remote
:
# Timeslot was deleted remotely, remove any local one
# Timeslot was deleted remotely, remove any local one
resolution
=
"
remove
"
resolution
=
"
remove
"
continue
elif
not
local
and
remote
:
elif
not
local
and
remote
:
# Timeslot was added remotely
# Timeslot was added remotely
resolution
=
"
add
"
resolution
=
"
add
"
merged_ts
.
append
(
remote
)
merged_ts
.
append
(
remote
)
elif
not
local
and
not
remote
:
elif
local
and
remote
:
# Timeslot existing locally, was updated or did not change remotely
# Update the local timeslot with possibly changed data
local
.
show
=
remote
.
show
local
.
episode
=
remote
.
episode
local
.
id
=
remote
.
id
local
.
repetition_id
=
remote
.
repetition_id
if
local
.
playlist
.
timeslot
:
local
.
playlist
.
timeslot
.
update_playlist
(
remote
.
playlist
.
timeslot
)
if
local
.
playlist
.
schedule
:
local
.
playlist
.
schedule
.
update_playlist
(
remote
.
playlist
.
schedule
)
if
local
.
playlist
.
show
:
local
.
playlist
.
show
.
update_playlist
(
remote
.
playlist
.
show
)
merged_ts
.
append
(
local
)
resolution
=
"
update
"
else
:
# Relations w/o local and remote timeslots should not happen
# Relations w/o local and remote timeslots should not happen
self
.
logger
(
SU
.
red
(
"
Skipping invalid merge case!
"
))
self
.
logger
.
critical
(
SU
.
red
(
"
Skipping invalid merge case!
"
))
resolution
=
"
skip
"
resolution
=
"
skip
"
merged_ts
.
append
(
remote
)
else
:
# Timeslot was updated or did not change
# Use the potentially newer, remote version
resolution
=
"
update
"
merged_ts
.
append
(
remote
)
local
=
"
local:
"
+
str
(
local
).
ljust
(
25
)
local
=
"
local:
"
+
str
(
local
).
ljust
(
25
)
remote
=
"
remote:
"
+
str
(
remote
).
ljust
(
25
)
remote
=
"
remote:
"
+
str
(
remote
).
ljust
(
25
)
...
...
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