Skip to content
Snippets Groups Projects
Commit 3bf4aaa0 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[scripts][jobs] Make it more automated to consult all of our runners

parent ed27283d
No related branches found
No related tags found
No related merge requests found
Pipeline #27730 passed
...@@ -104,6 +104,12 @@ def _echo(text, *args, **kwargs): ...@@ -104,6 +104,12 @@ def _echo(text, *args, **kwargs):
def echo_normal(text): def echo_normal(text):
"""Color preset for normal text output for :py:func:`click.echo`""" """Color preset for normal text output for :py:func:`click.echo`"""
click.echo(text)
def echo_info(text):
"""Color preset for normal text output for :py:func:`click.echo`"""
_echo(text, 'green') _echo(text, 'green')
......
...@@ -7,19 +7,24 @@ import click ...@@ -7,19 +7,24 @@ import click
from . import bdt from . import bdt
from ..release import get_gitlab_instance from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger, echo_normal from ..log import verbosity_option, get_logger, echo_normal, echo_info
logger = get_logger(__name__) logger = get_logger(__name__)
@click.command(epilog=''' @click.command(epilog='''
Examples: Examples:
1. List running jobs on a runner defined by its description (macmini): 1. List running jobs on any of our runners
$ bdt gitlab jobs -vv
2. List running jobs on a runner defined by its description:
$ bdt gitlab jobs -vv macmini $ bdt gitlab jobs -vv macmini
''') ''')
@click.argument('name') @click.argument('name', nargs=-1)
@click.option('-s', '--status', type=click.Choice(['running', 'success', @click.option('-s', '--status', type=click.Choice(['running', 'success',
'failed', 'canceled']), 'failed', 'canceled']),
default='running', show_default=True, default='running', show_default=True,
...@@ -28,26 +33,37 @@ Examples: ...@@ -28,26 +33,37 @@ Examples:
@verbosity_option() @verbosity_option()
@bdt.raise_on_error @bdt.raise_on_error
def jobs(name, status): def jobs(name, status):
"""Lists jobs on a given runner """Lists jobs on a given runner identified by description
""" """
gl = get_gitlab_instance() gl = get_gitlab_instance()
gl.auth() gl.auth()
user_id = gl.user.attributes['id'] user_id = gl.user.attributes['id']
# search for the runner to affect names = name or [
the_runner = [k for k in gl.runners.list(all=True) if \ 'linux-desktop-shell',
k.attributes['description'] == name] 'linux-desktop-docker',
if not the_runner: 'linux-server-shell',
raise RuntimeError('Cannot find runner with description = %s', name) 'linux-server-docker',
the_runner = the_runner[0] 'macpro',
logger.info('Found runner %s (id=%d)', 'macmini',
the_runner.attributes['description'], the_runner.attributes['id']) ]
jobs = the_runner.jobs.list(all=True, status=status) # search for the runner(s) to affect
logger.info('There are %d jobs running on %s', len(jobs), name) runners = [k for k in gl.runners.list(all=True) if \
for k in jobs: k.attributes['description'] in names]
echo_normal('** job %d: %s (%s), since %s, by %s [%s]' % \
(k.id, k.attributes['project']['path_with_namespace'], if not runners:
k.attributes['name'], k.attributes['started_at'], raise RuntimeError('Cannot find runner with description = %s' % \
k.attributes['user']['username'], k.attributes['web_url'])) '|'.join(names))
for runner in runners:
jobs = runner.jobs.list(all=True, status=status)
echo_normal('Runner %s (id=%d) -- %d running' % \
(runner.attributes['description'], runner.attributes['id'],
len(jobs)))
for k in jobs:
echo_info('** job %d: %s (%s), since %s, by %s [%s]' % \
(k.id, k.attributes['project']['path_with_namespace'],
k.attributes['name'], k.attributes['started_at'],
k.attributes['user']['username'], k.attributes['web_url']))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment