Skip to content

Commit

Permalink
Merge pull request #307 from istresearch/dev/next into develop
Browse files Browse the repository at this point in the history
add EXPORT_TASK_CHECK_HOURS env var instead of hard-coded 4 hours.
  • Loading branch information
baracudda authored Jul 24, 2023
2 parents 22c8714 + 988a032 commit 9b439b4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engage/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def ready(self):

from .views import BulkActionMixinOverrides
BulkActionMixinOverrides.setClassOverrides()

from .export import BaseExportTaskOverrides
BaseExportTaskOverrides.setClassOverrides()
#enddef ready

#endclass AppConfig
27 changes: 27 additions & 0 deletions engage/utils/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from datetime import timedelta

from django.conf import settings
from django.utils import timezone

from engage.utils.class_overrides import ClassOverrideMixinMustBeFirst, ignoreDjangoModelAttrs

from temba.utils.export import BaseExportTask

class BaseExportTaskOverrides(ClassOverrideMixinMustBeFirst, BaseExportTask):
override_ignore = ignoreDjangoModelAttrs(BaseExportTask)

# we do not want Django to perform any magic inheritance
class Meta:
abstract = True

@classmethod
def get_recent_unfinished(cls, org):
"""
Checks for unfinished exports created recently for this org, and returns the most recent
"""
recent_hours = settings.EXPORT_TASK_CHECK_HOURS if hasattr(settings, 'EXPORT_TASK_CHECK_HOURS') else 4
recent_past = timezone.now() - timedelta(hours=recent_hours)
return cls.get_unfinished().filter(org=org, created_on__gt=recent_past).order_by("created_on").last()
#enddef get_recent_unfinished

#endclass BaseExportTaskOverrides
2 changes: 2 additions & 0 deletions temba/settings_engage.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,5 @@
ALT_CALLBACK_DOMAIN = env('ALT_CALLBACK_DOMAIN', None)

ASYNC_MESSAGE_EXPORT = env('ASYNC_MESSAGE_EXPORT', 'on') == 'on'

EXPORT_TASK_CHECK_HOURS = env('EXPORT_TASK_CHECK_HOURS', 4)

0 comments on commit 9b439b4

Please sign in to comment.