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
afc557ec
Commit
afc557ec
authored
1 year ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
refactor: improve typing, debug and null handling
parent
33eb46b5
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
+18
-8
18 additions, 8 deletions
src/aura_engine/scheduling/timetable.py
with
18 additions
and
8 deletions
src/aura_engine/scheduling/timetable.py
+
18
−
8
View file @
afc557ec
...
...
@@ -200,6 +200,7 @@ class TimetableService:
# Iterate over all timeslots and find the one to be played right now
if
self
.
timetable
:
timeslot
:
Timeslot
for
timeslot
in
self
.
timetable
:
if
timeslot
.
get_start
()
<=
now
and
now
<
timeslot
.
get_end
():
current_timeslot
=
timeslot
...
...
@@ -320,7 +321,7 @@ class TimetableMerger:
self
.
config
=
AuraConfig
.
instance
.
config
self
.
logger
=
logging
.
getLogger
(
"
engine
"
)
def
build_map
(
self
,
local_timeslots
:
[
Timeslot
],
remote_timeslots
:
[
Timeslot
])
->
dict
:
def
build_map
(
self
,
local_timeslots
:
list
[
Timeslot
],
remote_timeslots
:
list
[
Timeslot
])
->
dict
:
"""
Build a map of local and remote timeslots relations.
...
...
@@ -334,7 +335,7 @@ class TimetableMerger:
Returns:
({str: {}}): Map with timestamp as key and a dictionary referencing timeslots.
"""
timeslot_map
:
{
str
:
{}}
=
{}
timeslot_map
:
dict
[
str
:
dict
]
=
{}
if
local_timeslots
:
for
ts
in
local_timeslots
:
if
not
timeslot_map
.
get
(
str
(
ts
.
get_start
())):
...
...
@@ -342,7 +343,7 @@ class TimetableMerger:
idx
=
timeslot_map
[
str
(
ts
.
get_start
())]
idx
[
"
local
"
]
=
ts
idx
[
"
remote
"
]
=
""
idx
[
"
remote
"
]
=
None
if
remote_timeslots
:
for
ts
in
remote_timeslots
:
...
...
@@ -352,10 +353,12 @@ class TimetableMerger:
idx
=
timeslot_map
[
str
(
ts
.
get_start
())]
idx
[
"
remote
"
]
=
ts
if
not
idx
.
get
(
"
local
"
):
idx
[
"
local
"
]
=
""
idx
[
"
local
"
]
=
None
return
timeslot_map
def
merge
(
self
,
local_timeslots
:
[
Timeslot
],
remote_timeslots
:
[
Timeslot
])
->
[
Timeslot
]:
def
merge
(
self
,
local_timeslots
:
list
[
Timeslot
],
remote_timeslots
:
list
[
Timeslot
]
)
->
list
[
Timeslot
]:
"""
Merge strategy for local and remote timeslots.
...
...
@@ -374,7 +377,7 @@ class TimetableMerger:
scheduling_window_start
=
self
.
config
.
scheduler
.
scheduling_window_start
now
:
float
=
SU
.
timestamp
()
resolution
:
str
=
""
self
.
logger
.
debug
(
"
\n
Map for timetable merge:
"
)
merge_info
=
SU
.
cyan
(
"
\n
Map for timetable merge:
"
)
for
timestamp
,
ts_relation
in
timeslot_map
.
items
():
local
=
ts_relation
.
get
(
"
local
"
)
...
...
@@ -382,7 +385,8 @@ class TimetableMerger:
if
(
float
(
timestamp
)
-
scheduling_window_start
)
<
now
:
# It's past the scheduling window, so keep the local one as is
merged_ts
.
append
(
local
)
if
local
:
merged_ts
.
append
(
local
)
resolution
=
"
skip
"
else
:
if
local
and
not
remote
:
...
...
@@ -393,6 +397,11 @@ class TimetableMerger:
# Timeslot was added remotely
resolution
=
"
add
"
merged_ts
.
append
(
remote
)
elif
not
local
and
not
remote
:
# Relations w/o local and remote timeslots should not happen
self
.
logger
(
SU
.
red
(
"
Skipping invalid merge case!
"
))
resolution
=
"
skip
"
merged_ts
.
append
(
remote
)
else
:
# Timeslot was updated or did not change
# Use the potentially newer, remote version
...
...
@@ -401,6 +410,7 @@ class TimetableMerger:
local
=
"
local:
"
+
str
(
local
).
ljust
(
25
)
remote
=
"
remote:
"
+
str
(
remote
).
ljust
(
25
)
self
.
logger
.
debug
(
f
"
\t
TIME:
{
timestamp
}
-
{
local
}
|
{
remote
}
↦ (
{
resolution
}
)
"
)
merge_info
+=
SU
.
cyan
(
f
"
\
n\
t
TIME:
{
timestamp
}
-
{
local
}
|
{
remote
}
↦ (
{
resolution
}
)
"
)
self
.
logger
.
debug
(
merge_info
+
"
\n
"
)
return
merged_ts
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