/
tasks.py
38 lines (33 loc) · 1010 Bytes
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from huey import crontab
from huey.contrib.djhuey import periodic_task, task
from numbas_lti.report_outcome import ReportOutcomeException
from numbas_lti.models import Attempt, ScormElement, diff_scormelements
from django.db.models import Count
from datetime import datetime
@task()
def editorlink_update_cache(el):
el.update_cache()
el.save()
@task()
def send_attempt_completion_receipt(attempt):
attempt.send_completion_receipt()
@task()
def resource_report_scores(resource):
resource.report_scores()
@task()
def attempt_report_outcome(attempt):
try:
attempt.report_outcome()
except ReportOutcomeException:
pass
@periodic_task(crontab(minute='*'))
def diff_suspend_data():
attempts = Attempt.objects.filter(diffed=False)
MAX_TIME = 10
start = datetime.now()
if attempts.exists():
for a in attempts:
diff_scormelements(a)
t2 = datetime.now()
if (t2-start).total_seconds()>MAX_TIME:
break