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
0e71690b
Commit
0e71690b
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Fixed remote deletion of timeslots. #41
parent
02a549b2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scheduling/programme.py
+38
-30
38 additions, 30 deletions
src/scheduling/programme.py
with
38 additions
and
30 deletions
src/scheduling/programme.py
+
38
−
30
View file @
0e71690b
...
...
@@ -283,8 +283,6 @@ class ProgrammePersistence(threading.Thread):
Timeslot ([]): An arrar of retrieved timeslots passed via `self.queue`
"""
result
=
[]
now_unix
=
SU
.
timestamp
()
scheduling_window_start
=
self
.
config
.
get
(
"
scheduling_window_start
"
)
try
:
fetched_timeslot_data
=
self
.
api_fetcher
.
fetch
()
...
...
@@ -296,30 +294,7 @@ class ProgrammePersistence(threading.Thread):
return
# Check if existing timeslots have been deleted
local_timeslots
=
Timeslot
.
get_timeslots
(
datetime
.
now
())
for
local_timeslot
in
local_timeslots
:
# Only allow deletion of timeslots which are deleted before the start of the scheduling window
if
local_timeslot
.
start_unix
>
now_unix
:
if
(
local_timeslot
.
start_unix
-
scheduling_window_start
)
>
now_unix
:
# Filter the local timeslot from the fetched ones
existing_timeslot
=
list
(
filter
(
lambda
new_timeslot
:
\
new_timeslot
[
"
timeslot_id
"
]
==
local_timeslot
.
timeslot_id
,
fetched_timeslot_data
))
if
existing_timeslot
:
# self.logger.debug("Timeslot #%s is still existing remotely!" % (local_timeslot.timeslot_id))
pass
else
:
self
.
logger
.
info
(
"
Timeslot #%s has been deleted remotely, hence also delete it locally [%s]
"
%
\
(
local_timeslot
.
timeslot_id
,
str
(
local_timeslot
)))
local_timeslot
.
delete
(
commit
=
True
)
self
.
logger
.
info
(
"
Deleted local timeslot #%s from database
"
%
local_timeslot
.
timeslot_id
)
else
:
msg
=
"
Timeslot #%s has been deleted remotely. Since the scheduling window has already started, it won
'
t be deleted locally.
"
%
\
local_timeslot
.
timeslot_id
self
.
logger
.
error
(
SU
.
red
(
msg
))
self
.
update_deleted_timeslots
(
fetched_timeslot_data
)
# Process fetched timeslots
for
timeslot
in
fetched_timeslot_data
:
...
...
@@ -358,6 +333,43 @@ class ProgrammePersistence(threading.Thread):
def
update_deleted_timeslots
(
self
,
fetched_timeslot_data
):
"""
Checks if some timeslot has been deleted remotely, so delete it locally too.
Attention: This method has no effect if only a single timeslot got deleted,
because this could simply indicate a issue with the API/Steering, since that
means no data got retrieved.
Args:
fetched_timeslot_data ([dict]): List of timeslot dictionaries from the API
"""
now_unix
=
SU
.
timestamp
()
scheduling_window_start
=
self
.
config
.
get
(
"
scheduling_window_start
"
)
local_timeslots
=
Timeslot
.
get_timeslots
(
datetime
.
now
())
for
local_timeslot
in
local_timeslots
:
# Ignore timeslots which have already started
if
local_timeslot
.
start_unix
>
now_unix
:
# Filter the local timeslot from the fetched ones
existing_remotely
=
list
(
filter
(
lambda
new_timeslot
:
\
new_timeslot
[
"
timeslot_id
"
]
==
local_timeslot
.
timeslot_id
,
fetched_timeslot_data
))
if
not
existing_remotely
:
# Only allow deletion of timeslots which are deleted before the start of the scheduling window
if
(
local_timeslot
.
start_unix
-
scheduling_window_start
)
>
now_unix
:
self
.
logger
.
info
(
"
Timeslot #%s has been deleted remotely, hence also delete it locally too [%s]
"
%
\
(
local_timeslot
.
timeslot_id
,
str
(
local_timeslot
)))
local_timeslot
.
delete
(
commit
=
True
)
self
.
logger
.
info
(
"
Remotely deleted timeslot #%s from local database
"
%
local_timeslot
.
timeslot_id
)
else
:
msg
=
"
Timeslot #%s has been deleted remotely. Since the scheduling window has already started, it won
'
t be deleted locally.
"
%
local_timeslot
.
timeslot_id
self
.
logger
.
error
(
SU
.
red
(
msg
))
def
store_timeslot
(
self
,
timeslot
):
"""
Stores the given timeslot to the database.
...
...
@@ -373,7 +385,6 @@ class ProgrammePersistence(threading.Thread):
timeslot_db
=
Timeslot
()
havetoadd
=
True
timeslot_db
.
show_id
=
timeslot
[
"
show_id
"
]
timeslot_db
.
timeslot_id
=
timeslot
[
"
timeslot_id
"
]
timeslot_db
.
timeslot_start
=
timeslot
[
"
start
"
]
...
...
@@ -387,19 +398,16 @@ class ProgrammePersistence(threading.Thread):
timeslot_db
.
category
=
timeslot
[
"
show_categories
"
]
timeslot_db
.
topic
=
timeslot
[
"
show_topics
"
]
timeslot_db
.
musicfocus
=
timeslot
[
"
show_musicfocus
"
]
timeslot_db
.
playlist_id
=
timeslot
[
"
playlist_id
"
]
timeslot_db
.
schedule_fallback_id
=
timeslot
[
"
schedule_fallback_id
"
]
timeslot_db
.
show_fallback_id
=
timeslot
[
"
show_fallback_id
"
]
timeslot_db
.
station_fallback_id
=
timeslot
[
"
station_fallback_id
"
]
timeslot_db
.
store
(
add
=
havetoadd
,
commit
=
True
)
return
timeslot_db
# def store_playlist(self, timeslot_db, playlist_id, fetched_playlist, fallbackplaylist_type=0):
def
store_playlist
(
self
,
timeslot_db
,
playlist_id
,
fetched_playlist
):
"""
Stores the Playlist to the database.
...
...
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