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
8238f144
Commit
8238f144
authored
8 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[scripts] Add scripts to process user job splits and run worker tasks
parent
b57f37d6
No related branches found
No related tags found
1 merge request
!194
Scheduler
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
beat/web/scripts/process.py
+108
-0
108 additions, 0 deletions
beat/web/scripts/process.py
beat/web/scripts/worker.py
+144
-0
144 additions, 0 deletions
beat/web/scripts/worker.py
setup.py
+2
-0
2 additions, 0 deletions
setup.py
with
254 additions
and
0 deletions
beat/web/scripts/process.py
0 → 100644
+
108
−
0
View file @
8238f144
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
"""
\
Processes one split.
Usage:
%(prog)s [--settings=<file>] [--cpulimit=<file>] [-v ...] <execute> <split>
%(prog)s (-h | --help)
%(prog)s (-V | --version)
Arguments:
<execute> The path to the base execution program for running the user code
<split> The primary-key of the split to treat by this subprocess
Options:
-h, --help Show this help message
-V, --version Show program
'
s version number
-v, --verbose Increases the output verbosity level
-S <file>, --settings=<file> The module name to the Django settings file
[default: beat.web.settings.settings]
-C <file>, --cpulimit=<file> The path to the cpulimit program to use. If
not set, CPU limiting is not enforced.
Examples:
To start the job split processing do the following:
$ %(prog)s <path-to-execute> <split-id>
You can optionally pass the ``-v`` flag to start the worker with the logging
level set to ``INFO`` or ``-vv`` to set it to ``DEBUG``. By default, the
logging level is set to ``WARNING`` if no ``-v`` flag is passed.
You can optionally also set the path to the ``cpulimit`` program to use. If
it is not set, then CPU limiting will not be enforced.
"""
import
logging
__logging_format__
=
'
[%(levelname)s] %(message)s
'
logging
.
basicConfig
(
format
=
__logging_format__
)
logger
=
logging
.
getLogger
(
__name__
)
import
os
import
sys
import
docopt
def
main
(
user_input
=
None
):
arguments
=
docopt
.
docopt
(
__doc__
%
dict
(
prog
=
os
.
path
.
basename
(
sys
.
argv
[
0
]),
),
)
# Sets-up logging
if
arguments
[
'
--verbose
'
]
==
1
:
logging
.
getLogger
().
setLevel
(
logging
.
INFO
)
elif
arguments
[
'
--verbose
'
]
>=
2
:
logging
.
getLogger
().
setLevel
(
logging
.
DEBUG
)
# Initializes the Django framework
os
.
environ
.
setdefault
(
'
DJANGO_SETTINGS_MODULE
'
,
arguments
[
'
--settings
'
])
from
django.conf
import
settings
from
django
import
setup
setup
()
from
beat.web.backend.schedule
import
process
process
(
split_pk
=
int
(
arguments
[
'
<split>
'
]),
execute
=
arguments
[
'
<execute>
'
],
cpulimit
=
arguments
[
'
--cpulimit
'
],
)
This diff is collapsed.
Click to expand it.
beat/web/scripts/worker.py
0 → 100644
+
144
−
0
View file @
8238f144
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
"""
\
Starts the worker process.
Usage:
%(prog)s [-v ... | --verbose ...] [--settings=<file>]
%(prog)s [--cpulimit=<file>] [--environments=<path>]
%(prog)s (-h | --help)
%(prog)s (-V | --version)
Options:
-h, --help Show this help message
-V, --version Show program
'
s version number
-v, --verbose Increases the output verbosity level
-S <file>, --settings=<file> The module name to the Django settings
file [default: beat.web.settings.settings]
-c <file>, --cpulimit=<file> The path to the cpulimit program to use. If
not set, try to search in standard
locations. If not found, CPU limiting is
not enforced.
-e <path>, --environments=<path> The path to the installation root of
available environments.
Examples:
To start the worker do the following:
$ %(prog)s
You can pass the ``-v`` flag to start the worker with the logging level set
to ``INFO`` or ``-vv`` to set it to ``DEBUG``. By default, the logging level
is set to ``WARNING`` if no ``-v`` flag is passed.
"""
import
logging
__logging_format__
=
'
[%(levelname)s] %(message)s
'
logging
.
basicConfig
(
format
=
__logging_format__
)
logger
=
logging
.
getLogger
(
__name__
)
import
os
import
sys
import
time
import
signal
import
docopt
def
main
(
user_input
=
None
):
stop
=
False
# installs SIGTERM handler
def
handler
(
signum
,
frame
):
stop
=
True
signal
.
signal
(
signal
.
SIGTERM
,
handler
)
arguments
=
docopt
.
docopt
(
__doc__
%
dict
(
prog
=
os
.
path
.
basename
(
sys
.
argv
[
0
]),
),
)
# Sets-up logging
if
arguments
[
'
--verbose
'
]
==
1
:
logging
.
getLogger
().
setLevel
(
logging
.
INFO
)
elif
arguments
[
'
--verbose
'
]
>=
2
:
logging
.
getLogger
().
setLevel
(
logging
.
DEBUG
)
try
:
from
beat.core.async
import
resolve_cpulimit_path
cpulimit
=
resolve_cpulimit_path
(
arguments
[
'
--cpulimit
'
])
from
beat.web.backend.schedule
import
find_environments
,
work
from
beat.web.backend.schedule
import
resolve_process_path
from
beat.web.backend.schedule
import
worker_shutdown
,
worker_update
process
=
resolve_process_path
()
environments
=
find_environments
(
arguments
[
'
--environments
'
]
or
[])
os
.
environ
.
setdefault
(
'
DJANGO_SETTINGS_MODULE
'
,
arguments
[
'
--settings
'
])
from
django.conf
import
settings
from
django
import
setup
setup
()
worker_update
()
last_update
=
time
.
time
()
timing
=
settings
.
WORKER_INTERVAL
while
not
stop
:
start
=
time
.
time
()
work
(
environments
,
cpulimit
,
process
)
currtime
=
time
.
time
()
duration
=
currtime
-
start
if
duration
<
settings
.
WORKER_INTERVAL
:
time
.
sleep
(
settings
.
WORKER_INTERVAL
-
duration
)
if
(
last_update
-
currtime
)
>
settings
.
WORKER_STATE_UPDATE
:
worker_update
()
except
Exception
:
from
traceback
import
format_exc
logger
.
error
(
format_exc
())
finally
:
worker_shutdown
()
This diff is collapsed.
Click to expand it.
setup.py
+
2
−
0
View file @
8238f144
...
@@ -87,6 +87,8 @@ setup(
...
@@ -87,6 +87,8 @@ setup(
entry_points
=
{
entry_points
=
{
'
console_scripts
'
:
[
'
console_scripts
'
:
[
'
localhost.py = beat.web.scripts.localhost:main
'
,
'
localhost.py = beat.web.scripts.localhost:main
'
,
'
process.py = beat.web.scripts.process:main
'
,
'
worker.py = beat.web.scripts.worker:main
'
,
],
],
},
},
...
...
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