Skip to content

Commit

Permalink
Fix clean download data task (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer authored May 8, 2024
1 parent e81d1e7 commit 0ef4ce8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion admin/download_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DownloadRequestAdmin(admin.ModelAdmin):
list_display = (
'uuid', 'first_name', 'last_name', 'organization',
'organization_types',
'email', 'country', 'request_at'
'email', 'country', 'request_at', 'age_hours'
)
filter_horizontal = ('countries',)
search_fields = (
Expand Down
6 changes: 6 additions & 0 deletions models/download_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from django.contrib.gis.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

from gwml2.models.general import Country
Expand Down Expand Up @@ -209,3 +210,8 @@ def file(self):
return file
else:
return None

@property
def age_hours(self):
diff = timezone.now() - self.request_at
return diff.total_seconds() / (60 * 60)
6 changes: 2 additions & 4 deletions tasks/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from celery import shared_task
from celery.utils.log import get_task_logger
from django.utils import timezone

from gwml2.models.download_request import DownloadRequest

Expand All @@ -11,13 +10,12 @@

@shared_task(
bind=True,
name='gwml2.tasks.harvester.clean_download_file',
name='gwml2.tasks.clean.clean_download_file',
queue='geoserver.events')
def clean_download_file(self):
"""Run clean download file."""
for download in DownloadRequest.objects.all():
diff = timezone.now() - download.request_at
if diff.days >= 1:
if download.age_hours >= 5:
_file = download.file()
if _file:
os.remove(_file)

0 comments on commit 0ef4ce8

Please sign in to comment.