Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
AURA
engine
Commits
ca7ee1bd
Commit
ca7ee1bd
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Send coordinator emails on fallback.
#38
parent
900ff081
No related branches found
No related tags found
No related merge requests found
Pipeline
#876
passed
4 years ago
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/mailer.py
+56
-10
56 additions, 10 deletions
src/plugins/mailer.py
with
56 additions
and
10 deletions
src/plugins/mailer.py
+
56
−
10
View file @
ca7ee1bd
...
...
@@ -39,8 +39,10 @@ class AuraMailer():
"""
Event handler to send emails to Aura administrators and programme coordinators.
"""
logger
=
None
engine
=
None
mail
=
None
previous_timeslot
=
None
def
__init__
(
self
,
engine
):
"""
...
...
@@ -49,6 +51,7 @@ class AuraMailer():
Args:
engine (Engine): The Engine
"""
self
.
logger
=
logging
.
getLogger
(
"
AuraEngine
"
)
self
.
engine
=
engine
self
.
mail
=
MailService
()
...
...
@@ -58,13 +61,36 @@ class AuraMailer():
#
def
on_fallback_active
(
self
,
timeslot
,
fallback_type
):
"""
Called when a fallback is activated for the given timeslot,
since no default playlist is available.
"""
show
=
"
EMPTY TIMESLOT
"
show_id
=
""
timeframe
=
""
if
timeslot
:
show
=
timeslot
.
show_name
show_id
=
"
The ID of the show is:
"
+
str
(
timeslot
.
show_id
)
timeframe
=
SU
.
fmt_time
(
timeslot
.
start_unix
)
+
"
-
"
+
SU
.
fmt_time
(
timeslot
.
end_unix
)
subject
=
f
"
Fallback for show
'
{
show
}
'
activated
"
message
=
"
Dear programme coordinator,
\n\n
"
message
+=
f
"
AURA would like to notify you, that a
'
{
fallback_type
}
'
fallback for show
'
{
show
}
'
(
{
timeframe
}
) just got activated.
"
message
+=
f
"
{
show_id
}
\n\n
Stay tuned!
"
self
.
logger
.
debug
(
message
)
self
.
mail
.
notify_coordinator
(
subject
,
message
)
def
on_sick
(
self
,
data
):
"""
Called when the engine is in some unhealthy state.
"""
subject
=
"
ERROR - Engine turned into some INVALID STATE!
"
message
=
"
There
'
s an issue with your AURA Engine
'
%s
'
:
\n\n
%s
"
%
(
data
.
get
(
"
engine_id
"
),
data
.
get
(
"
status
"
))
self
.
mail
.
send
_admin
(
subject
,
message
)
self
.
mail
.
notify
_admin
(
subject
,
message
)
...
...
@@ -74,7 +100,7 @@ class AuraMailer():
"""
subject
=
"
OK - Engine became healthy again
"
message
=
"
Good news, things seem fine again with your AURA Engine
'
%s
'
:
\n\n
%s
"
%
(
data
.
get
(
"
engine_id
"
),
data
.
get
(
"
status
"
))
self
.
mail
.
send
_admin
(
subject
,
message
)
self
.
mail
.
notify
_admin
(
subject
,
message
)
...
...
@@ -83,7 +109,7 @@ class AuraMailer():
Callend when some critical event occurs
"""
if
not
data
:
data
=
""
self
.
mail
.
send
_admin
(
subject
,
message
+
"
\n\n
"
+
str
(
data
))
self
.
mail
.
notify
_admin
(
subject
,
message
+
"
\n\n
"
+
str
(
data
))
...
...
@@ -96,7 +122,8 @@ class MailService():
logger
=
None
admin_mails
=
None
admin_mails_enabled
=
None
coordinator_mails
=
None
coordinator_mails_enabled
=
None
def
__init__
(
self
):
"""
...
...
@@ -106,16 +133,17 @@ class MailService():
self
.
logger
=
logging
.
getLogger
(
"
AuraEngine
"
)
self
.
admin_mails
=
self
.
config
.
get
(
"
admin_mail
"
)
self
.
admin_mails_enabled
=
self
.
config
.
get
(
"
mail_admin_enabled
"
)
self
.
coordinator_mails
=
self
.
config
.
get
(
"
coordinator_mail
"
)
self
.
coordinator_mails_enabled
=
self
.
config
.
get
(
"
mail_coordinator_enabled
"
)
#
# METHODS
#
def
send
_admin
(
self
,
subject
,
body
):
def
notify
_admin
(
self
,
subject
,
body
):
"""
Sends an email to the administrator as defined in the configuration.
Sends an email to the administrator
(s)
as defined in the configuration.
Args:
subject (String): The email subject
...
...
@@ -132,6 +160,25 @@ class MailService():
def
notify_coordinator
(
self
,
subject
,
body
):
"""
Sends an email to the programme coordinator(s) as defined in the configuration.
Args:
subject (String): The email subject
body (String): The email body text
"""
if
self
.
coordinator_mails_enabled
==
"
false
"
:
self
.
logger
.
warning
(
SU
.
yellow
(
"
No programme coordinator mail sent, because doing so is disabled in engine.ini!
"
))
return
False
coordinator_mails
=
self
.
coordinator_mails
.
split
()
for
mail_to
in
coordinator_mails
:
self
.
send
(
mail_to
,
subject
,
body
)
def
send
(
self
,
mail_to
,
subject
,
body
):
"""
Sends an email to the given address.
...
...
@@ -140,14 +187,13 @@ class MailService():
subject (String): The email
'
s subject
body (String): The email
'
s body text
"""
# read config
mail_server
=
self
.
config
.
get
(
"
mail_server
"
)
mail_port
=
self
.
config
.
get
(
"
mail_server_port
"
)
mail_user
=
self
.
config
.
get
(
"
mail_user
"
)
mail_pass
=
self
.
config
.
get
(
"
mail_pass
"
)
from_mail
=
self
.
config
.
get
(
"
from_mail
"
)
#
c
heck settings
#
C
heck settings
if
mail_server
==
""
:
raise
MailingException
(
"
Mail Server not set
"
)
if
mail_port
==
""
:
...
...
@@ -159,7 +205,7 @@ class MailService():
if
from_mail
==
""
:
raise
MailingException
(
"
From Mail not set
"
)
#
stuff
the message
together
and ...
#
Compile
the message and ...
msg
=
EmailMessage
()
msg
.
set_content
(
body
)
mailsubject_prefix
=
self
.
config
.
get
(
"
mailsubject_prefix
"
)
...
...
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