Skip to content

Commit

Permalink
Add config option daemon.default_workers
Browse files Browse the repository at this point in the history
This option will determine the default number of workers that are
started by the `verdi daemon start` command. Specifying an explicit
value as argument will of course still override this.
  • Loading branch information
sphuber committed Apr 21, 2020
1 parent 0936512 commit 14835fa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
21 changes: 14 additions & 7 deletions aiida/cmdline/commands/cmd_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
from aiida.manage.configuration import get_config


def validate_positive_non_zero_integer(ctx, param, value): # pylint: disable=unused-argument,invalid-name
"""Validate that `value` is a positive integer."""
def validate_daemon_workers(ctx, param, value): # pylint: disable=unused-argument,invalid-name
"""Validate the value for the number of daemon workers to start with default set by config."""
if value is None:
value = ctx.obj.config.get_option('daemon.default_workers', ctx.obj.profile.name)

if not isinstance(value, int):
raise click.BadParameter('{} is not an integer'.format(value))

Expand All @@ -43,11 +46,15 @@ def verdi_daemon():

@verdi_daemon.command()
@click.option('--foreground', is_flag=True, help='Run in foreground.')
@click.argument('number', default=1, type=int, callback=validate_positive_non_zero_integer)
@click.argument('number', required=False, type=int, callback=validate_daemon_workers)
@decorators.with_dbenv()
@decorators.check_circus_zmq_version
def start(foreground, number):
"""Start the daemon with NUMBER workers [default=1]."""
"""Start the daemon with NUMBER workers.
If the NUMBER of desired workers is not specified, the default is used, which is determined by the configuration
option `daemon.default_workers`, which if not explicitly changed defaults to 1.
"""
from aiida.engine.daemon.client import get_daemon_client

client = get_daemon_client()
Expand Down Expand Up @@ -196,8 +203,8 @@ def restart(ctx, reset, no_wait):
"""Restart the daemon.
By default will only reset the workers of the running daemon. After the restart the same amount of workers will be
running. If the `--reset` flag is passed, however, the full circus daemon will be stopped and restarted with just
a single worker.
running. If the `--reset` flag is passed, however, the full daemon will be stopped and restarted with the default
number of workers that is started when calling `verdi daemon start` manually.
"""
from aiida.engine.daemon.client import get_daemon_client

Expand All @@ -223,7 +230,7 @@ def restart(ctx, reset, no_wait):

@verdi_daemon.command(hidden=True)
@click.option('--foreground', is_flag=True, help='Run in foreground.')
@click.argument('number', default=1, type=int, callback=validate_positive_non_zero_integer)
@click.argument('number', required=False, type=int, callback=validate_daemon_workers)
@decorators.with_dbenv()
@decorators.check_circus_zmq_version
def start_circus(foreground, number):
Expand Down
9 changes: 9 additions & 0 deletions aiida/manage/configuration/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
__all__ = ('get_option', 'get_option_names', 'parse_option')

NO_DEFAULT = ()
DEFAULT_DAEMON_WORKERS = 1
DEFAULT_DAEMON_TIMEOUT = 20 # Default timeout in seconds for circus client calls
VALID_LOG_LEVELS = ['CRITICAL', 'ERROR', 'WARNING', 'REPORT', 'INFO', 'DEBUG']

Expand All @@ -30,6 +31,14 @@
'description': 'The polling interval in seconds to be used by process runners',
'global_only': False,
},
'daemon.default_workers': {
'key': 'daemon_default_workers',
'valid_type': 'int',
'valid_values': None,
'default': DEFAULT_DAEMON_WORKERS,
'description': 'The default number of workers to be launched by `verdi daemon start`',
'global_only': False,
},
'daemon.timeout': {
'key': 'daemon_timeout',
'valid_type': 'int',
Expand Down
2 changes: 1 addition & 1 deletion docs/source/verdi/verdi_user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ Below is a list with all available subcommands.
incr Add NUMBER [default=1] workers to the running daemon.
logshow Show the log of the daemon, press CTRL+C to quit.
restart Restart the daemon.
start Start the daemon with NUMBER workers [default=1].
start Start the daemon with NUMBER workers.
status Print the status of the current daemon or all daemons.
stop Stop the daemon.

Expand Down
1 change: 0 additions & 1 deletion tests/cmdline/commands/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for `verdi daemon`."""

from click.testing import CliRunner
import pytest

Expand Down

0 comments on commit 14835fa

Please sign in to comment.