From ade2b84d0da634a26823bc8aed0ee770d668cc8c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 11 Jun 2018 09:41:17 +0200 Subject: [PATCH] we can use signals due to the fact that cron jobs are run in single thread --- smash/web/models/constants.py | 2 +- smash/web/redcap_connector.py | 2 +- smash/web/views/kit.py | 13 +------------ smash/web/views/voucher.py | 2 +- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/smash/web/models/constants.py b/smash/web/models/constants.py index 9873fce4..ad7354a0 100644 --- a/smash/web/models/constants.py +++ b/smash/web/models/constants.py @@ -82,7 +82,7 @@ REDCAP_TOKEN_CONFIGURATION_TYPE = "REDCAP_TOKEN_CONFIGURATION_TYPE" REDCAP_BASE_URL_CONFIGURATION_TYPE = "REDCAP_BASE_URL_CONFIGURATION_TYPE" # timeout job after 15 minutes -CRON_JOB_TIMEOUT = 15 * 60 * 1000 +CRON_JOB_TIMEOUT = 15 * 60 COUNTRY_OTHER_ID = 1 COUNTRY_AFGHANISTAN_ID = 2 diff --git a/smash/web/redcap_connector.py b/smash/web/redcap_connector.py index 57090743..7d448fc6 100644 --- a/smash/web/redcap_connector.py +++ b/smash/web/redcap_connector.py @@ -323,7 +323,7 @@ class RedCapRefreshJob(CronJobBase): schedule = Schedule(run_every_mins=RUN_EVERY_MINUTES) code = 'web.red_cap_hourly_refresh' # a unique code - @timeout_decorator.timeout(CRON_JOB_TIMEOUT, use_signals=False) + @timeout_decorator.timeout(CRON_JOB_TIMEOUT) def do(self): connector = RedcapConnector() if connector.is_valid(): diff --git a/smash/web/views/kit.py b/smash/web/views/kit.py index 5d728430..6448b098 100644 --- a/smash/web/views/kit.py +++ b/smash/web/views/kit.py @@ -141,37 +141,26 @@ class KitRequestEmailSendJob(CronJobBase): schedule = Schedule(run_every_mins=RUN_EVERY_MINUTES) code = 'web.kit_request_weekly_email' # a unique code - @timeout_decorator.timeout(CRON_JOB_TIMEOUT, use_signals=False) + @timeout_decorator.timeout(CRON_JOB_TIMEOUT) def do(self): - print "X" now = datetime.datetime.utcnow() - print "X4" hour = int(ConfigurationItem.objects.get( type=KIT_EMAIL_HOUR_CONFIGURATION_TYPE).value.split(":")[0]) - print "X3" minute = int(ConfigurationItem.objects.get( type=KIT_EMAIL_HOUR_CONFIGURATION_TYPE).value.split(":")[1]) - print "2" # check if we sent email this day already date = now.replace(hour=hour, minute=minute) - print "1" # TODO it's a hack assuming that we are in CEST date = pytz.utc.localize(date - datetime.timedelta(minutes=122)) - print "a" jobs = CronJobLog.objects.filter(code=KitRequestEmailSendJob.code, message="mail sent", start_time__gte=date) - print "Y" if jobs.count() == 0: - print "Ya" if pytz.utc.localize(datetime.datetime.utcnow()) > date: - print "Ys" if self.match_day_of_week(): - print "Yd" worker = Worker.objects.create() data = get_kit_requests(worker) send_mail(data) worker.delete() - print "Ye" return "mail sent" else: return "day of week doesn't match" diff --git a/smash/web/views/voucher.py b/smash/web/views/voucher.py index 34300963..53234277 100644 --- a/smash/web/views/voucher.py +++ b/smash/web/views/voucher.py @@ -81,7 +81,7 @@ class ExpireVouchersJob(CronJobBase): code = 'web.voucher_expiry_job' # a unique code # noinspection PyMethodMayBeStatic - @timeout_decorator.timeout(CRON_JOB_TIMEOUT, use_signals=False) + @timeout_decorator.timeout(CRON_JOB_TIMEOUT) def do(self): due_date = get_today_midnight_date() vouchers = Voucher.objects.filter(status=VOUCHER_STATUS_NEW, expiry_date__lte=due_date) -- GitLab