forked from GithubBackups/healthchecks
Add the pruneflips
management command.
This commit is contained in:
parent
b37d908879
commit
c0d808271e
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
### Improvements
|
### Improvements
|
||||||
- Show the number of downtimes and total downtime minutes in monthly reports (#104)
|
- Show the number of downtimes and total downtime minutes in monthly reports (#104)
|
||||||
- Show the number of downtimes and total downtime minutes in "Check Details" page
|
- Show the number of downtimes and total downtime minutes in "Check Details" page
|
||||||
|
- Add the `pruneflips` management command
|
||||||
|
|
||||||
|
|
||||||
## 1.8.0 - 2019-07-08
|
## 1.8.0 - 2019-07-08
|
||||||
|
11
README.md
11
README.md
@ -269,7 +269,7 @@ There are separate Django management commands for each task:
|
|||||||
$ ./manage.py pruneusers
|
$ ./manage.py pruneusers
|
||||||
```
|
```
|
||||||
|
|
||||||
* Remove old records fromt he `api_tokenbucket` table. The TokenBucket
|
* Remove old records from the `api_tokenbucket` table. The TokenBucket
|
||||||
model is used for rate-limiting login attempts and similar operations.
|
model is used for rate-limiting login attempts and similar operations.
|
||||||
Any records older than one day can be safely removed.
|
Any records older than one day can be safely removed.
|
||||||
|
|
||||||
@ -277,6 +277,15 @@ There are separate Django management commands for each task:
|
|||||||
$ ./manage.py prunetokenbucket
|
$ ./manage.py prunetokenbucket
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Remove old records from the `api_flip` table. The Flip
|
||||||
|
objects are used to track status changes of checks, and to calculate
|
||||||
|
downtime statistics month by month. Flip objects from more than 3 months
|
||||||
|
ago are not used and can be safely removed.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ./manage.py pruneflips
|
||||||
|
```
|
||||||
|
|
||||||
When you first try these commands on your data, it is a good idea to
|
When you first try these commands on your data, it is a good idea to
|
||||||
test them on a copy of your database, not on the live database right away.
|
test them on a copy of your database, not on the live database right away.
|
||||||
In a production setup, you should also have regular, automated database
|
In a production setup, you should also have regular, automated database
|
||||||
|
16
hc/api/management/commands/pruneflips.py
Normal file
16
hc/api/management/commands/pruneflips.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from hc.api.models import Flip
|
||||||
|
from hc.lib.date import month_boundaries
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Prune old Flip objects."
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
threshold = min(month_boundaries(months=3))
|
||||||
|
|
||||||
|
q = Flip.objects.filter(created__lt=threshold)
|
||||||
|
n_pruned, _ = q.delete()
|
||||||
|
|
||||||
|
return "Done! Pruned %d flips." % n_pruned
|
Loading…
x
Reference in New Issue
Block a user