Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
beat
beat.web
Commits
02969f77
Commit
02969f77
authored
8 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[backend] Check worker environments
parent
8837f11a
No related branches found
No related tags found
1 merge request
!194
Scheduler
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
beat/web/backend/models.py
+38
-0
38 additions, 0 deletions
beat/web/backend/models.py
beat/web/backend/views.py
+16
-0
16 additions, 0 deletions
beat/web/backend/views.py
beat/web/scripts/worker.py
+18
-1
18 additions, 1 deletion
beat/web/scripts/worker.py
todo.rst
+6
-0
6 additions, 0 deletions
todo.rst
with
78 additions
and
1 deletion
beat/web/backend/models.py
+
38
−
0
View file @
02969f77
...
...
@@ -260,6 +260,44 @@ class Worker(models.Model):
return
dict
(
cores
=
self
.
cores
,
memory
=
self
.
memory
)
def
check_environments
(
self
,
environments
):
'''
Checks that this worker has access to all environments it needs
This method will check if the found set of environments (in the
dictionary ``environments``) contains, at least, one environment for
each environment object this worker is supposed to be able to execute
user algorithms for.
Parameters:
environments (dict): A dictionary of environments found by using
:py:func:`utils.find_environments` in which, keys represent the
natural keys of Django database environments.
Returns:
list: A list of missing environments this worker can be assigned to
work with, but where not found
list: A list of unused environments this worker cannot be assigned to
work with, but where nevertheless found
'''
slots
=
Slot
.
objects
.
filter
(
worker
=
self
)
queues
=
Queue
.
objects
.
filter
(
slots__in
=
slots
)
wishlist
=
Environment
.
objects
.
filter
(
queues__in
=
queues
)
wishlist
=
wishlist
.
order_by
(
'
id
'
).
distinct
()
required
=
[
k
.
natural_key
()
for
k
in
wishlist
]
missing
=
[
k
for
k
in
required
if
k
not
in
environments
]
unused
=
[
k
for
k
in
environments
if
k
not
in
required
]
return
missing
,
unused
def
update_state
(
self
):
'''
Updates state on the database based on current machine readings
'''
...
...
This diff is collapsed.
Click to expand it.
beat/web/backend/views.py
+
16
−
0
View file @
02969f77
...
...
@@ -66,10 +66,26 @@ class Work:
def
__setup__
(
self
):
Work
.
cpulimit
=
resolve_cpulimit_path
(
None
)
logger
.
debug
(
"
(path) cpulimit: `%s
'"
,
Work
.
cpulimit
)
Work
.
process
=
utils
.
resolve_process_path
()
logger
.
debug
(
"
(path) process: `%s
'"
,
Work
.
process
)
Work
.
environments
=
utils
.
find_environments
(
None
)
logger
.
debug
(
"
Environments: %s
"
,
"
,
"
.
join
(
Work
.
environments
))
# load worker, check environments, activate it
w
=
Worker
.
objects
.
get
(
name
=
socket
.
gethostname
())
\
if
Worker
.
objects
.
count
()
!=
1
else
Worker
.
objects
.
get
()
missing
,
unused
=
w
.
check_environments
(
Work
.
environments
)
if
unused
:
logger
.
info
(
"
The following environments where found on your
"
\
"
setup, but will not be used with the current queue
"
\
"
configuration: %s
"
%
"
,
"
.
join
(
unused
))
if
missing
:
raise
RuntimeError
(
"
The following environments are currently
"
\
"
missing from your setup: %s
"
%
"
,
"
.
join
(
missing
))
else
:
logger
.
info
(
"
All required software environments were found
"
)
w
.
activate
()
w
.
save
()
Work
.
worker
=
w
...
...
This diff is collapsed.
Click to expand it.
beat/web/scripts/worker.py
+
18
−
1
View file @
02969f77
...
...
@@ -117,15 +117,32 @@ def main(user_input=None):
from
beat.core.async
import
resolve_cpulimit_path
cpulimit
=
resolve_cpulimit_path
(
arguments
[
'
--cpulimit
'
])
logger
.
debug
(
"
(path) cpulimit: `%s
'"
,
cpulimit
)
process
=
utils
.
resolve_process_path
()
logger
.
debug
(
"
(path) process: `%s
'"
,
process
)
environments
=
utils
.
find_environments
(
arguments
[
'
--environments
'
])
logger
.
debug
(
"
Environments: %s
"
,
"
,
"
.
join
(
environments
))
worker
=
Worker
.
objects
.
get
(
name
=
arguments
[
'
--name
'
])
# check environments
missing
,
unused
=
worker
.
check_environments
(
environments
)
if
unused
:
logger
.
info
(
"
The following environments where found on your
"
\
"
setup, but will not be used with the current queue
"
\
"
configuration: %s
"
%
"
,
"
.
join
(
unused
))
if
missing
:
raise
RuntimeError
(
"
The following environments are currently
"
\
"
missing from your setup: %s
"
%
"
,
"
.
join
(
missing
))
else
:
logger
.
info
(
"
All required software environments were found
"
)
timing
=
int
(
arguments
[
'
--period
'
])
\
if
arguments
[
'
--period
'
]
else
settings
.
WORKER_INTERVAL
logger
.
info
(
"
Working at `%s
'
every %d seconds
"
,
arguments
[
'
--name
'
],
timing
)
global
stop
with
Worker
.
objects
.
get
(
name
=
arguments
[
'
--name
'
])
as
worker
:
with
worker
:
while
not
stop
:
...
...
This diff is collapsed.
Click to expand it.
todo.rst
+
6
−
0
View file @
02969f77
...
...
@@ -59,3 +59,9 @@ Experiments
* Make sure to remove any spurious logs from the beat.scheduler before
introducing stdout/stderr components to the experiment view
Backend
-------
* Add proper e-mail queueing support
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