Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
0a87700f
Commit
0a87700f
authored
1 month ago
by
Philipp Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add ExpiringEvents to count number events within a type window
parent
3a6c64da
No related branches found
Branches containing commit
No related tags found
1 merge request
!1134
[job_monitor] Watch and warn of jobs failing (almost) instantly by host
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_job_monitor.py
+16
-0
16 additions, 0 deletions
tests/test_job_monitor.py
webservice/job_monitor.py
+29
-0
29 additions, 0 deletions
webservice/job_monitor.py
with
45 additions
and
0 deletions
tests/test_job_monitor.py
0 → 100644
+
16
−
0
View file @
0a87700f
import
pytest
import
time
from
webservice.job_monitor
import
ExpiringEvents
def
test_expiring_events
():
ev
=
ExpiringEvents
(
600
)
assert
ev
.
add
()
==
1
assert
ev
.
add
()
==
2
assert
ev
.
add
(
time
.
monotonic
()
-
800
)
==
2
assert
ev
.
add
()
==
3
assert
len
(
ev
)
==
3
This diff is collapsed.
Click to expand it.
webservice/job_monitor.py
+
29
−
0
View file @
0a87700f
...
...
@@ -7,6 +7,8 @@ import os.path
import
shlex
import
signal
import
time
from
bisect
import
insort_left
from
collections
import
deque
from
datetime
import
datetime
,
timezone
from
pathlib
import
Path
from
subprocess
import
run
,
PIPE
...
...
@@ -38,6 +40,33 @@ STATE_ABBREVS = {
}
class
ExpiringEvents
:
"""
Track events occuring within a time window.
Args:
window (int, optional): Time window in seconds, 600 by default.
"""
def
__init__
(
self
,
window
=
600
):
self
.
window
=
window
self
.
events
=
deque
()
def
add
(
self
,
event
=
None
):
now
=
time
.
monotonic
()
insort_left
(
self
.
events
,
event
or
now
)
cutoff
=
now
-
self
.
window
while
self
.
events
and
self
.
events
[
0
]
<
cutoff
:
self
.
events
.
popleft
()
return
len
(
self
.
events
)
def
__len__
(
self
):
return
len
(
self
.
events
)
class
NoOpProducer
:
"""
Fills in for Kafka producer object when setting that up fails
"""
def
send
(
self
,
topic
,
value
):
...
...
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