Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
dab3f542
Commit
dab3f542
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Delete old data check results for no longer persisting problems
parent
c7fae2a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!580
Resolve "Remove old data check results if the data problem persists no longer"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/data_checks.py
+30
-2
30 additions, 2 deletions
aleksis/core/data_checks.py
with
30 additions
and
2 deletions
aleksis/core/data_checks.py
+
30
−
2
View file @
dab3f542
import
logging
from
django.apps
import
apps
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models.aggregates
import
Count
from
django.utils.functional
import
classproperty
...
...
@@ -156,11 +157,19 @@ class DataCheck:
solve_options
=
{
IgnoreSolveOption
.
name
:
IgnoreSolveOption
}
_current_results
=
[]
@classmethod
def
check_data
(
cls
):
"""
Find all objects with data issues and register them.
"""
pass
@classmethod
def
run_check_data
(
cls
):
"""
Wrap ``check_data`` to ensure that post-processing tasks are run.
"""
cls
.
check_data
()
cls
.
delete_old_results
()
@classmethod
def
solve
(
cls
,
check_result
:
"
DataCheckResult
"
,
solve_option
:
str
):
"""
Execute a solve option for an object detected by this check.
...
...
@@ -188,11 +197,30 @@ class DataCheck:
from
aleksis.core.models
import
DataCheckResult
ct
=
ContentType
.
objects
.
get_for_model
(
instance
)
result
=
DataCheckResult
.
objects
.
get_or_create
(
result
,
__
=
DataCheckResult
.
objects
.
get_or_create
(
check
=
cls
.
name
,
content_type
=
ct
,
object_id
=
instance
.
id
)
# Track all existing problems (for deleting old results)
cls
.
_current_results
.
append
(
result
)
return
result
@classmethod
def
delete_old_results
(
cls
):
"""
Delete old data check results for problems which exist no longer.
"""
DataCheckResult
=
apps
.
get_model
(
"
core
"
,
"
DataCheckResult
"
)
pks
=
[
r
.
pk
for
r
in
cls
.
_current_results
]
old_results
=
DataCheckResult
.
objects
.
filter
(
check
=
cls
.
name
).
exclude
(
pk__in
=
pks
)
if
old_results
:
logging
.
info
(
f
"
Delete
{
old_results
.
count
()
}
old data check results.
"
)
old_results
.
delete
()
# Reset list with existing problems
cls
.
_current_results
=
[]
class
DataCheckRegistry
:
"""
Create central registry for all data checks in AlekSIS.
"""
...
...
@@ -213,7 +241,7 @@ def check_data(recorder: ProgressRecorder):
"""
Execute all registered data checks and send email if activated.
"""
for
check
in
recorder
.
iterate
(
DataCheckRegistry
.
data_checks
):
logging
.
info
(
f
"
Run check:
{
check
.
verbose_name
}
"
)
check
.
check_data
()
check
.
run_
check_data
()
if
get_site_preferences
()[
"
general__data_checks_send_emails
"
]:
send_emails_for_data_checks
()
...
...
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