Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
d6c809a4
Commit
d6c809a4
authored
Jul 23, 2023
by
HeJ
Browse files
Options
Downloads
Patches
Plain Diff
housekeeping: flag CachedSchedules which need a regeneration
parent
cb168ae5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/management/commands/housekeeping.py
+40
-1
40 additions, 1 deletion
src/core/management/commands/housekeeping.py
with
40 additions
and
1 deletion
src/core/management/commands/housekeeping.py
+
40
−
1
View file @
d6c809a4
import
time
import
time
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.db.models
import
Max
from
django.utils
import
timezone
from
django.utils
import
timezone
from
...models.conference
import
Conference
from
...models.messages
import
DirectMessage
from
...models.messages
import
DirectMessage
from
...models.schedules
import
ScheduleSource
,
ScheduleSourceImport
from
...models.schedules
import
CachedSchedule
,
ScheduleSource
,
ScheduleSourceImport
from
...models.voucher
import
Voucher
from
...models.voucher
import
Voucher
...
@@ -14,16 +16,24 @@ class Command(BaseCommand):
...
@@ -14,16 +16,24 @@ class Command(BaseCommand):
parser
.
add_argument
(
'
--forever-delay
'
,
type
=
int
,
default
=
300
,
help
=
'
seconds to wait between housekeeping runs
'
)
parser
.
add_argument
(
'
--forever-delay
'
,
type
=
int
,
default
=
300
,
help
=
'
seconds to wait between housekeeping runs
'
)
def
_do_housekeeping
(
self
):
def
_do_housekeeping
(
self
):
self
.
_housekeeping_directmessages
()
self
.
_housekeeping_vouchers
()
self
.
_housekeeping_scheduleimports
()
self
.
_housekeeping_schedulecaching
()
def
_housekeeping_directmessages
(
self
):
# clear all direct messages which are after their expiry date
# clear all direct messages which are after their expiry date
print
(
'
Deleting messages ...
'
,
end
=
''
,
flush
=
True
)
print
(
'
Deleting messages ...
'
,
end
=
''
,
flush
=
True
)
deleted_msgs_count
,
_
=
DirectMessage
.
objects
.
filter
(
autodelete_after__isnull
=
False
,
autodelete_after__lte
=
timezone
.
now
()).
delete
()
deleted_msgs_count
,
_
=
DirectMessage
.
objects
.
filter
(
autodelete_after__isnull
=
False
,
autodelete_after__lte
=
timezone
.
now
()).
delete
()
print
(
deleted_msgs_count
)
print
(
deleted_msgs_count
)
def
_housekeeping_vouchers
(
self
):
# do auto-assignments
# do auto-assignments
print
(
'
Auto-assigning vouchers ...
'
,
end
=
''
,
flush
=
True
)
print
(
'
Auto-assigning vouchers ...
'
,
end
=
''
,
flush
=
True
)
vouchers_assigned
=
Voucher
.
do_auto_assignments
()
vouchers_assigned
=
Voucher
.
do_auto_assignments
()
print
(
vouchers_assigned
)
print
(
vouchers_assigned
)
def
_housekeeping_scheduleimports
(
self
):
# schedules
# schedules
print
(
'
Schedule imports ...
'
,
end
=
''
,
flush
=
True
)
print
(
'
Schedule imports ...
'
,
end
=
''
,
flush
=
True
)
schedule_results
=
{}
schedule_results
=
{}
...
@@ -60,6 +70,35 @@ class Command(BaseCommand):
...
@@ -60,6 +70,35 @@ class Command(BaseCommand):
for
k
,
v
in
schedule_results
.
items
():
for
k
,
v
in
schedule_results
.
items
():
print
(
'
'
,
k
,
'
=>
'
,
v
,
sep
=
''
)
print
(
'
'
,
k
,
'
=>
'
,
v
,
sep
=
''
)
def
_housekeeping_schedulecaching
(
self
):
ref
=
{}
for
c
in
Conference
.
objects
.
all
():
ts
=
[]
ts
.
append
(
c
.
tracks
.
aggregate
(
Max
(
'
last_update
'
))[
'
last_update__max
'
])
ts
.
append
(
c
.
events
.
aggregate
(
Max
(
'
last_update
'
))[
'
last_update__max
'
])
ts
.
append
(
c
.
rooms
.
aggregate
(
Max
(
'
last_update
'
))[
'
last_update__max
'
])
ref
[
c
.
id
]
=
max
([
x
for
x
in
ts
if
x
is
not
None
],
default
=
None
)
changed
,
total
=
0
,
0
for
entry
in
CachedSchedule
.
objects
.
all
():
total
+=
1
# entries already marked for regeneration don't need further action
if
entry
.
needs_regeneration
:
continue
# ignore cache entries with a newer generation entry
ref_ts
=
ref
[
entry
.
conference_id
]
if
ref_ts
is
not
None
and
entry
.
last_generated
>
ref_ts
:
continue
# flag this entry for regeneration
entry
.
needs_regeneration
=
True
entry
.
save
(
update_fields
=
[
'
needs_regeneration
'
])
changed
+=
1
print
(
'
Flagged
'
,
changed
,
'
out of
'
,
total
,
'
cached schedules for regeneration.
'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
# call _do_housekeeping repeatedly (unless --forever is not set)
# call _do_housekeeping repeatedly (unless --forever is not set)
forever
=
options
.
get
(
'
forever
'
)
forever
=
options
.
get
(
'
forever
'
)
...
...
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
sign in
to comment