Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nk20-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
BDE
nk20-scripts
Commits
e59001b1
Commit
e59001b1
authored
4 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Send a mail to webmasters when an error occurs (in production mode)
parent
256ac0a7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__init__.py
+4
-0
4 additions, 0 deletions
__init__.py
apps.py
+14
-0
14 additions, 0 deletions
apps.py
signals.py
+38
-0
38 additions, 0 deletions
signals.py
with
56 additions
and
0 deletions
__init__.py
+
4
−
0
View file @
e59001b1
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
default_app_config
=
'
scripts.apps.ScriptsConfig
'
This diff is collapsed.
Click to expand it.
apps.py
0 → 100644
+
14
−
0
View file @
e59001b1
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from
django.apps
import
AppConfig
from
django.core.signals
import
got_request_exception
class
ScriptsConfig
(
AppConfig
):
name
=
'
scripts
'
def
ready
(
self
):
from
.
import
signals
print
(
"
scripts are ready
"
)
got_request_exception
.
connect
(
signals
.
send_mail_on_exception
)
This diff is collapsed.
Click to expand it.
signals.py
0 → 100644
+
38
−
0
View file @
e59001b1
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
os
import
sys
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.template.loader
import
render_to_string
from
django.views.debug
import
ExceptionReporter
def
send_mail_on_exception
(
request
,
**
kwargs
):
"""
When an error occurs on the Note Kfet, a mail is automatically sent to the webmasters.
"""
if
settings
.
DEBUG
:
# Don't need to send a mail in debug mode, errors are already displayed in console and in the response view.
return
try
:
exc_info
=
sys
.
exc_info
()
exc_type
=
exc_info
[
0
]
exc
=
exc_info
[
1
]
tb
=
exc_info
[
2
]
reporter
=
ExceptionReporter
(
request
=
request
,
exc_type
=
exc_type
,
exc_value
=
exc
,
tb
=
tb
)
note_sender
=
os
.
getenv
(
"
NOTE_MAIL
"
,
"
notekfet@example.com
"
)
webmaster
=
os
.
getenv
(
"
WEBMASTER_MAIL
"
,
"
notekfet@example.com
"
)
message
=
render_to_string
(
'
scripts/mail-error500.txt
'
,
context
=
{
"
error
"
:
reporter
.
get_traceback_text
()})
message_html
=
render_to_string
(
'
scripts/mail-error500.html
'
,
context
=
{
"
error
"
:
reporter
.
get_traceback_html
()})
send_mail
(
"
Erreur dans la Note Kfet
"
,
message
,
note_sender
,
[
webmaster
],
html_message
=
message_html
)
except
BaseException
as
e
:
sys
.
stderr
.
write
(
"
Une erreur est survenue lors de l
'
envoi d
'
un mail, pour signaler une erreur.
"
)
raise
e
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