Browse Source

Add the `pruneflips` management command.

pull/272/head
Pēteris Caune 5 years ago
parent
commit
c0d808271e
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 27 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +10
    -1
      README.md
  3. +16
    -0
      hc/api/management/commands/pruneflips.py

+ 1
- 0
CHANGELOG.md View File

@ -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


+ 10
- 1
README.md View File

@ -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
- 0
hc/api/management/commands/pruneflips.py View 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…
Cancel
Save