Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
d75bb1c3
Commit
d75bb1c3
authored
5 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
mails can be sent multiple time per day
parent
28f1b764
No related branches found
No related tags found
1 merge request
!240
Redcap sync
Pipeline
#25330
failed
5 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/views/kit.py
+17
-24
17 additions, 24 deletions
smash/web/views/kit.py
with
17 additions
and
24 deletions
smash/web/views/kit.py
+
17
−
24
View file @
d75bb1c3
...
...
@@ -2,11 +2,10 @@
import
datetime
import
locale
import
logging
import
traceback
import
platform
import
time
import
traceback
import
pytz
import
timeout_decorator
from
django.contrib
import
messages
from
django.utils.dateparse
import
parse_datetime
...
...
@@ -221,36 +220,30 @@ def kit_requests_send_mail(request, start_date, end_date=None):
class
KitRequestEmailSendJob
(
CronJobBase
):
RUN_EVERY_MINUTES
=
1
schedule
=
Schedule
(
run_every_mins
=
RUN_EVERY_MINUTES
)
RUN_AT
=
[]
times
=
ConfigurationItem
.
objects
.
get
(
type
=
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
).
value
.
split
(
"
;
"
)
for
entry
in
times
:
# TODO it's a hack assuming that we are in CEST
text
=
str
((
int
(
entry
.
split
(
"
:
"
)[
0
])
+
22
)
%
24
)
+
"
:
"
+
entry
.
split
(
"
:
"
)[
1
]
RUN_AT
.
append
(
text
)
schedule
=
Schedule
(
run_at_times
=
RUN_AT
)
code
=
'
web.kit_request_weekly_email
'
# a unique code
@timeout_decorator.timeout
(
CRON_JOB_TIMEOUT
)
def
do
(
self
):
now
=
datetime
.
datetime
.
utcnow
()
hour
=
int
(
ConfigurationItem
.
objects
.
get
(
type
=
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
).
value
.
split
(
"
:
"
)[
0
])
minute
=
int
(
ConfigurationItem
.
objects
.
get
(
type
=
KIT_EMAIL_HOUR_CONFIGURATION_TYPE
).
value
.
split
(
"
:
"
)[
1
])
# check if we sent email this day already
date
=
now
.
replace
(
hour
=
hour
,
minute
=
minute
)
# TODO it's a hack assuming that we are in CEST
date
=
pytz
.
utc
.
localize
(
date
-
datetime
.
timedelta
(
minutes
=
122
))
jobs
=
CronJobLog
.
objects
.
filter
(
code
=
KitRequestEmailSendJob
.
code
,
message
=
"
mail sent
"
,
start_time__gte
=
date
)
code
=
KitRequestEmailSendJob
.
code
,
message
=
"
mail sent
"
,
start_time__gte
=
date
time
.
datetime
.
utcnow
()
)
if
jobs
.
count
()
==
0
:
if
pytz
.
utc
.
localize
(
datetime
.
datetime
.
utcnow
())
>
date
:
if
self
.
match_day_of_week
():
worker
=
Worker
.
objects
.
create
()
data
=
get_kit_requests
(
worker
)
send_mail
(
data
)
worker
.
delete
()
return
"
mail sent
"
else
:
return
"
day of week doesn
'
t match
"
if
self
.
match_day_of_week
():
worker
=
Worker
.
objects
.
create
()
data
=
get_kit_requests
(
worker
)
send_mail
(
data
)
worker
.
delete
()
return
"
mail sent
"
else
:
return
"
too early
"
return
"
day of week doesn
'
t match
"
else
:
return
"
mail already sent
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment