-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
151 lines (117 loc) · 4.18 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from datetime import datetime, time, timedelta
from celery import shared_task
from django.core.mail import send_mail
from extra.models import Feedback
from namingalgorithm.models import UserSubmission
@shared_task
def run_needle(filename):
try:
align = submit_single_sequence.align.run_bug(filename)
return align
except IOError as e:
print(e)
def trigger_email_everyday():
#name, email = extract_email()
sequence_message = """Dear Dr.Neil Crickmore and Dr.Colin Berry,
There is a new sequence submission in the database. Please check the database admin page for more details."""
send_mail(
subject="New Submission for the database",
message=sequence_message,
from_email="[email protected]",
recipient_list=[
],
fail_silently=False,
)
def trigger_email_everyday_feedback():
sequence_message = """Dear Dr.Neil Crickmore and Dr.Colin Berry,
There is a new feedback in the database page. Please check the database admin Feedback page for more details."""
send_mail(
subject="New Feedback for the database",
message=sequence_message,
from_email="[email protected]",
recipient_list=[
],
fail_silently=False,
)
def trigger_email_bpprc_SSL_status():
sequence_message = """Dear Dr.Neil Crickmore and Dr.Colin Berry,
There is a new feedback in the database page. Please check the bpprc site SSL certification status. It appears not secure"""
send_mail(
subject="BPPRC SSL status",
message=sequence_message,
from_email="[email protected]",
recipient_list=["[email protected]"],
fail_silently=False,
)
def trigger_email_camtech_SSL_status():
sequence_message = """Dear Dr.Neil Crickmore and Dr.Colin Berry,
There is a new feedback in the database page. Please check the camtech database site SSL certification status. It appears not secure"""
send_mail(
subject="camtech database SSL status",
message=sequence_message,
from_email="[email protected]",
recipient_list=["[email protected]"],
fail_silently=False,
)
def feedback():
today = datetime.now().date()
tomorrow = today + timedelta(1)
today_start = datetime.combine(today, time())
today_end = datetime.combine(tomorrow, time())
return Feedback.objects.filter(
uploaded__gte=datetime.date(today_start),
uploaded__lte=datetime.date(today_end),
)
def filter_by_date():
today = datetime.now().date()
tomorrow = today + timedelta(1)
today_start = datetime.combine(today, time())
today_end = datetime.combine(tomorrow, time())
return UserSubmission.objects.filter(
uploaded__gte=datetime.date(today_start),
uploaded__lte=datetime.date(today_end),
)
def extract_email():
name, email = ''
id = UserSubmission.objects.latest('id')
if id.submittersname:
name = id.submittersname
if id.submittersemail:
email = id.submittersemail
return name, email
@shared_task
def run():
print("I am the email job")
if filter_by_date():
# Model.objects.latest('field')
trigger_email_everyday()
if feedback():
trigger_email_everyday_feedback()
# https://medium.com/@yedjoe/celery-4-periodic-task-in-django-9f6b5a8c21c7
# def sleep_sometime():
# schedule.run_pending()
# time.sleep(60)
#
# schedule.every().day.at("17:25").do(check_new_submission())
@shared_task
def check_bpprc_ssl_status():
print("I check the SSL status of bpprc site")
import requests
try:
requests.get("https://www.bpprc.org", verify=True)
except SSLError:
trigger_email_bpprc_SSL_status()
@shared_task
def check_camtech_ssl_status():
print("I check the SSL status of bpprc site")
import requests
try:
requests.get("https://camtech-bpp.ifas.ufl.edu/", verify=True)
except SSLError:
trigger_email_camtech_SSL_status()