Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
2f4cb25f
Commit
2f4cb25f
authored
2 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Maily o chybách: Obecná funkce na odesílání
parent
69380288
No related branches found
No related tags found
1 merge request
!120
Mailové upozornění na interní chyby
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
etc/config.py.example
+3
-0
3 additions, 0 deletions
etc/config.py.example
mo/email.py
+37
-1
37 additions, 1 deletion
mo/email.py
with
40 additions
and
1 deletion
etc/config.py.example
+
3
−
0
View file @
2f4cb25f
...
...
@@ -25,6 +25,9 @@ MAIL_CONTACT = "osmo@mo.mff.cuni.cz"
# Odesilatel generovaných mailů (není-li definován, neposílají se)
# MAIL_FROM = "osmo-auto@mo.mff.cuni.cz"
# Kam posíláme maily o interních chybách (není-li definováno, neposílají se)
# MAIL_ERRORS_TO = "osmo@mo.mff.cuni.cz"
# Pro testování je možné všechny odesílané maily přesměrovat na jinou adresu
# MAIL_INSTEAD = "mares@kam.mff.cuni.cz"
...
...
This diff is collapsed.
Click to expand it.
mo/email.py
+
37
−
1
View file @
2f4cb25f
...
...
@@ -5,11 +5,14 @@ import email.message
import
email.headerregistry
import
subprocess
import
textwrap
import
token_bucket
import
traceback
from
typing
import
Mapping
,
Optional
import
urllib.parse
import
mo.db
as
db
import
mo.config
as
config
from
mo.util
import
logger
from
mo.util
import
logger
,
ExceptionInfo
def
send_email
(
send_to
:
str
,
full_name
:
str
,
subject
:
str
,
body
:
str
)
->
bool
:
...
...
@@ -177,3 +180,36 @@ def send_grading_info_email(dest: db.User, round: db.Round) -> bool:
Váš OSMO
'''
),
add_footer
=
True
)
# Omezení rychlosti odesílání mailů o chybách děravým kyblíkem
# (pozor, každý proces má svůj kyblík)
error_tbf
=
token_bucket
.
Limiter
(
rate
=
1
/
300
,
capacity
=
10
,
storage
=
token_bucket
.
MemoryStorage
())
errors_supressed
=
0
def
send_internal_error_email
(
place
:
str
,
attrs
:
Mapping
[
str
,
Optional
[
str
]],
exc_info
:
ExceptionInfo
):
errors_to
=
getattr
(
config
,
'
MAIL_ERRORS_TO
'
,
None
)
if
errors_to
is
None
:
return
global
errors_supressed
if
not
error_tbf
.
consume
(
key
=
"
K
"
):
errors_supressed
+=
1
logger
.
info
(
'
Mail: Příliš mnoho chybových zpráv
'
)
return
exc_type
,
exc_value
,
exc_traceback
=
exc_info
lines
=
[
f
'
{
key
+
"
:
"
:
10
s
}
{
val
if
val
is
not
None
else
"
-
"
}
\n
'
for
key
,
val
in
sorted
(
attrs
.
items
())]
if
exc_traceback
is
not
None
:
lines
.
append
(
'
\n
'
)
lines
.
extend
(
traceback
.
format_exception
(
exc_type
,
exc_value
,
exc_traceback
))
if
errors_supressed
>
0
:
lines
.
append
(
'
\n
'
)
lines
.
append
(
f
'
### Předchozích
{
errors_supressed
}
chyb neohlášeno
\n
'
)
logger
.
info
(
'
Mail: Zpráva o interní chybě
'
)
send_email
(
errors_to
,
""
,
f
'
Interní chyba (
{
place
}
)
'
,
""
.
join
(
lines
))
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