1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Move CHANGELOG_RETENTION to dyanmic configuration

This commit is contained in:
jeremystretch
2021-11-08 15:07:58 -05:00
parent 3292a2aecc
commit 2a00519b93
7 changed files with 26 additions and 21 deletions

View File

@@ -31,7 +31,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin):
'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'),
}),
('Miscellaneous', {
'fields': ('MAINTENANCE_MODE', 'MAPS_URL'),
'fields': ('MAINTENANCE_MODE', 'CHANGELOG_RETENTION', 'MAPS_URL'),
}),
('Config Revision', {
'fields': ('comment',),

View File

@@ -10,12 +10,14 @@ from django.utils import timezone
from packaging import version
from extras.models import ObjectChange
from netbox.config import Config
class Command(BaseCommand):
help = "Perform nightly housekeeping tasks. (This command can be run at any time.)"
def handle(self, *args, **options):
config = Config()
# Clear expired authentication sessions (essentially replicating the `clearsessions` command)
if options['verbosity']:
@@ -37,10 +39,10 @@ class Command(BaseCommand):
# Delete expired ObjectRecords
if options['verbosity']:
self.stdout.write("[*] Checking for expired changelog records")
if settings.CHANGELOG_RETENTION:
cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
if config.CHANGELOG_RETENTION:
cutoff = timezone.now() - timedelta(days=config.CHANGELOG_RETENTION)
if options['verbosity'] >= 2:
self.stdout.write(f"\tRetention period: {settings.CHANGELOG_RETENTION} days")
self.stdout.write(f"\tRetention period: {config.CHANGELOG_RETENTION} days")
self.stdout.write(f"\tCut-off time: {cutoff}")
expired_records = ObjectChange.objects.filter(time__lt=cutoff).count()
if expired_records:
@@ -58,7 +60,7 @@ class Command(BaseCommand):
self.stdout.write("\tNo expired records found.", self.style.SUCCESS)
elif options['verbosity']:
self.stdout.write(
f"\tSkipping: No retention period specified (CHANGELOG_RETENTION = {settings.CHANGELOG_RETENTION})"
f"\tSkipping: No retention period specified (CHANGELOG_RETENTION = {config.CHANGELOG_RETENTION})"
)
# Check for new releases (if enabled)