Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aura-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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Lars Kruse
aura-engine
Commits
13679533
Commit
13679533
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Delete schedules out of the scheduling window only
parent
18fc34e5
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
modules/scheduling/calendar.py
+24
-13
24 additions, 13 deletions
modules/scheduling/calendar.py
with
24 additions
and
13 deletions
modules/scheduling/calendar.py
+
24
−
13
View file @
13679533
...
@@ -85,12 +85,15 @@ class AuraCalendarService(threading.Thread):
...
@@ -85,12 +85,15 @@ class AuraCalendarService(threading.Thread):
def
run
(
self
):
def
run
(
self
):
"""
"""
Fetch calendar data and store it in the database
Fetch calendar data and store it in the database. Also handles local deletion of remotely
deleted schedules.
Returns
Returns
Schedule ([]): An arrar of retrieved schedules passed via `self.queue`
Schedule ([]): An arrar of retrieved schedules passed via `self.queue`
"""
"""
result
=
[]
result
=
[]
now_unix
=
SimpleUtil
.
timestamp
()
scheduling_window_start
=
self
.
config
.
get
(
"
scheduling_window_start
"
)
try
:
try
:
fetched_schedule_data
=
self
.
calendar_fetcher
.
fetch
()
fetched_schedule_data
=
self
.
calendar_fetcher
.
fetch
()
...
@@ -103,21 +106,29 @@ class AuraCalendarService(threading.Thread):
...
@@ -103,21 +106,29 @@ class AuraCalendarService(threading.Thread):
# Check if existing schedules have been deleted
# Check if existing schedules have been deleted
local_schedules
=
Schedule
.
select_programme
(
datetime
.
now
())
local_schedules
=
Schedule
.
select_programme
(
datetime
.
now
())
for
local_schedule
in
local_schedules
:
for
local_schedule
in
local_schedules
:
# Filter the local schedule from the fetched ones
# Only allow deletion of schedules which are before the start of the scheduling window
existing_schedule
=
list
(
filter
(
lambda
new_schedule
:
\
if
local_schedule
.
start_unix
>
now_unix
and
(
local_schedule
.
start_unix
-
scheduling_window_start
)
>
now_unix
:
new_schedule
[
"
schedule_id
"
]
==
local_schedule
.
schedule_id
,
fetched_schedule_data
))
# Filter the local schedule from the fetched ones
if
existing_schedule
:
existing_schedule
=
list
(
filter
(
lambda
new_schedule
:
\
self
.
logger
.
debug
(
"
Schedule (schedule_id: %s) is still existing remotely:
"
%
\
new_schedule
[
"
schedule_id
"
]
==
local_schedule
.
schedule_id
,
fetched_schedule_data
))
(
local_schedule
.
schedule_id
))
if
existing_schedule
:
# self.logger.debug("Schedule #%s is still existing remotely!" % (local_schedule.schedule_id))
pass
else
:
self
.
logger
.
info
(
"
Schedule #%s has been deleted remotely, hence also delete it locally [%s]
"
%
\
(
local_schedule
.
schedule_id
,
str
(
local_schedule
)))
local_schedule
.
delete
(
commit
=
True
)
self
.
logger
.
info
(
"
Deleted local schedule #%s from database
"
%
local_schedule
.
schedule_id
)
else
:
else
:
self
.
logger
.
info
(
"
Schedule (schedule_id:
%s
)
has been deleted remotely
! [%s]
"
%
\
msg
=
"
Schedule #
%s has been deleted remotely
. Since the scheduling window already started, it won
'
t be deleted locally.
"
%
local_schedule
.
schedule_id
(
local_schedule
.
schedule_id
,
str
(
local_schedule
)
))
self
.
logger
.
warn
(
SimpleUtil
.
red
(
msg
))
local_schedule
.
delete
(
commit
=
True
)
self
.
logger
.
info
(
"
Deleted local schedule from database (schedule_id: %s)
"
%
local_schedule
.
schedule_id
)
# Process fetched schedules
# Process fetched schedules
...
...
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