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

we can use signals due to the fact that cron jobs are run in single thread

parent 7fb64f0b
No related branches found
No related tags found
2 merge requests!142Resolve "label for referral letter",!140cron jobs should be killed if hang
Pipeline #
......@@ -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
......
......@@ -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():
......
......@@ -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"
......
......@@ -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)
......
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