Skip to content
Snippets Groups Projects
Commit f2b9bf3a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

EXPORT_RUN_AT changed into configuration option

parent 97d481aa
No related branches found
No related tags found
1 merge request!271Resolve "clean configuration"
......@@ -3,12 +3,11 @@ import logging
import traceback
import timeout_decorator
from django.conf import settings
from django_cron import CronJobBase, Schedule
from web.models import ConfigurationItem
from web.models.constants import CRON_JOB_TIMEOUT, DEFAULT_FROM_EMAIL, DAILY_SUBJECT_EXPORT_FILE, \
DAILY_VISIT_EXPORT_FILE
DAILY_VISIT_EXPORT_FILE, SUBJECT_EXPORT_RUN_AT, VISIT_EXPORT_RUN_AT
from web.smash_email import EmailSender
from .exporter import SubjectExporter, VisitExporter
......@@ -16,7 +15,10 @@ logger = logging.getLogger(__name__)
class SubjectExporterCronJob(CronJobBase):
RUN_AT_TIMES = getattr(settings, "EXPORT_RUN_AT", ['23:55'])
item = ConfigurationItem.objects.filter(type=SUBJECT_EXPORT_RUN_AT).first()
RUN_AT_TIMES = []
if item is not None:
RUN_AT_TIMES = item.value.split(';')
schedule = Schedule(run_at_times=RUN_AT_TIMES)
code = 'web.export_subject_daily_job' # a unique code
......@@ -49,7 +51,10 @@ class SubjectExporterCronJob(CronJobBase):
class VisitExporterCronJob(CronJobBase):
RUN_AT_TIMES = getattr(settings, "EXPORT_RUN_AT", ['23:55'])
item = ConfigurationItem.objects.filter(type=VISIT_EXPORT_RUN_AT).first()
RUN_AT_TIMES = []
if item is not None:
RUN_AT_TIMES = item.value.split(';')
schedule = Schedule(run_at_times=RUN_AT_TIMES)
code = 'web.export_visit_daily_job' # a unique code
......
......@@ -3,7 +3,7 @@ from django.conf import settings
from django.db import migrations
from web.models.constants import DEFAULT_FROM_EMAIL, DAILY_SUBJECT_IMPORT_FILE, DAILY_SUBJECT_EXPORT_FILE, \
DAILY_VISIT_IMPORT_FILE, DAILY_VISIT_EXPORT_FILE, SUBJECT_IMPORT_RUN_AT
DAILY_VISIT_IMPORT_FILE, DAILY_VISIT_EXPORT_FILE, SUBJECT_IMPORT_RUN_AT, SUBJECT_EXPORT_RUN_AT, VISIT_EXPORT_RUN_AT
def create_item(apps, item_type, value, name):
......@@ -41,6 +41,13 @@ def configuration_items(apps, schema_editor):
create_item(apps, SUBJECT_IMPORT_RUN_AT, ';'.join(subject_import_run_at_times),
"At what times should the subject importer run")
export_run_at_times = getattr(settings, "EXPORT_RUN_AT", ['23:55'])
create_item(apps, SUBJECT_EXPORT_RUN_AT, ';'.join(export_run_at_times),
"At what times should the subject exporter run")
create_item(apps, VISIT_EXPORT_RUN_AT, ';'.join(export_run_at_times),
"At what times should the visit exporter run")
class Migration(migrations.Migration):
dependencies = [
......
......@@ -62,6 +62,8 @@ DAILY_SUBJECT_EXPORT_FILE = "DAILY_SUBJECT_EXPORT_FILE"
DAILY_VISIT_IMPORT_FILE = "DAILY_VISIT_IMPORT_FILE"
DAILY_VISIT_EXPORT_FILE = "DAILY_VISIT_EXPORT_FILE"
SUBJECT_IMPORT_RUN_AT = "SUBJECT_IMPORT_RUN_AT"
SUBJECT_EXPORT_RUN_AT = "SUBJECT_EXPORT_RUN_AT"
VISIT_EXPORT_RUN_AT = "VISIT_EXPORT_RUN_AT"
RED_CAP_LANGUAGE_4_FIELD_TYPE = 'RED_CAP_LANGUAGE_4_FIELD_TYPE'
RED_CAP_LANGUAGE_3_FIELD_TYPE = 'RED_CAP_LANGUAGE_3_FIELD_TYPE'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment