Skip to content

Commit 5920c68

Browse files
committed
verdi profile setup: Add --broker (aiidateam#7284)
Add `--broker` option to `verdi profile setup` accepting 'rabbitmq', 'zmq', or 'none'. Deprecate the `--use-rabbitmq/--no-use-rabbitmq` flag with a warning pointing to the new option. Add daemon restart logic to `verdi profile configure-rabbitmq` so broker reconfiguration takes effect immediately.
1 parent 5785eaf commit 5920c68

3 files changed

Lines changed: 53 additions & 13 deletions

File tree

src/aiida/cmdline/commands/cmd_presto.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def verdi_presto(
190190
broker. To switch to RabbitMQ later, use `verdi profile configure-rabbitmq`.
191191
"""
192192
from aiida.brokers.rabbitmq.defaults import detect_rabbitmq_config
193-
from aiida.brokers.zmq.defaults import get_zmq_config
194193
from aiida.common import exceptions
195194
from aiida.manage.configuration import create_profile, load_profile
196195
from aiida.orm import Computer
@@ -226,14 +225,14 @@ def verdi_presto(
226225
if use_zmq:
227226
echo.echo_report('`--use-zmq` enabled: configuring the profile with ZMQ broker.')
228227
broker_backend = 'core.zmq'
229-
broker_config = get_zmq_config()
228+
broker_config = {}
230229
else:
231230
try:
232231
broker_config = detect_rabbitmq_config()
233232
except ConnectionError:
234233
echo.echo_report('RabbitMQ server not found: falling back to ZMQ broker.')
235234
broker_backend = 'core.zmq'
236-
broker_config = get_zmq_config()
235+
broker_config = {}
237236
else:
238237
echo.echo_report('RabbitMQ server detected: configuring the profile with RabbitMQ broker.')
239238
broker_backend = 'core.rabbitmq'

src/aiida/cmdline/commands/cmd_profile.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def command_create_profile(
3636
first_name: str | None = None,
3737
last_name: str | None = None,
3838
institution: str | None = None,
39-
use_rabbitmq: bool = True,
39+
broker: str = 'rabbitmq',
40+
use_rabbitmq: bool | None = None,
4041
**kwargs,
4142
):
4243
"""Create a new profile, initialise its storage and create a default user.
@@ -51,10 +52,17 @@ def command_create_profile(
5152
:param first_name: First name for the default user.
5253
:param last_name: Last name for the default user.
5354
:param institution: Institution for the default user.
54-
:param use_rabbitmq: Whether to configure RabbitMQ as the broker.
55+
:param broker: Message broker backend ('rabbitmq', 'zmq', or 'none').
56+
:param use_rabbitmq: Deprecated. Use ``broker`` instead. If False, equivalent to ``broker='none'``.
5557
:param kwargs: Arguments to initialise instance of the selected storage implementation.
5658
"""
57-
from aiida.brokers.rabbitmq.defaults import detect_rabbitmq_config
59+
# Handle deprecated --use-rabbitmq/--no-use-rabbitmq option
60+
if use_rabbitmq is not None:
61+
from aiida.common.warnings import warn_deprecation
62+
63+
warn_deprecation('The `--use-rabbitmq` option is deprecated. Use `--broker` instead.', version=3)
64+
if not use_rabbitmq:
65+
broker = 'none'
5866
from aiida.common import docs
5967
from aiida.plugins.entry_point import get_entry_point_from_class
6068

@@ -70,7 +78,9 @@ def command_create_profile(
7078
broker_backend = None
7179
broker_config = None
7280

73-
if use_rabbitmq:
81+
if broker == 'rabbitmq':
82+
from aiida.brokers.rabbitmq.defaults import detect_rabbitmq_config
83+
7484
try:
7585
broker_config = detect_rabbitmq_config()
7686
except ConnectionError as exception:
@@ -80,8 +90,15 @@ def command_create_profile(
8090
broker_backend = 'core.rabbitmq'
8191

8292
echo.echo_report('RabbitMQ can be reconfigured with `verdi profile configure-rabbitmq`.')
83-
else:
84-
echo.echo_report('Creating profile without RabbitMQ.')
93+
94+
elif broker == 'zmq':
95+
broker_backend = 'core.zmq'
96+
broker_config = {}
97+
echo.echo_success('ZMQ broker configured (no external service required).')
98+
echo.echo_report('The ZMQ broker service will be started automatically with the daemon.')
99+
100+
else: # broker == 'none'
101+
echo.echo_report('Creating profile without a message broker.')
85102
echo.echo_report('It can be configured at a later point in time with `verdi profile configure-rabbitmq`.')
86103
echo.echo_report(f'See {docs.URL_NO_BROKER} for details on the limitations of running without a broker.')
87104

@@ -124,7 +141,8 @@ def command_create_profile(
124141
setup.SETUP_USER_FIRST_NAME(),
125142
setup.SETUP_USER_LAST_NAME(),
126143
setup.SETUP_USER_INSTITUTION(),
127-
setup.SETUP_USE_RABBITMQ(),
144+
setup.SETUP_BROKER_BACKEND(),
145+
setup.SETUP_USE_RABBITMQ(), # Deprecated, for backward compatibility
128146
],
129147
)
130148
def profile_setup():
@@ -161,12 +179,26 @@ def profile_configure_rabbitmq(ctx, /, profile, non_interactive, force, **kwargs
161179
else:
162180
echo.echo_success('Connected to RabbitMQ with the provided connection parameters')
163181

182+
from aiida.engine.daemon.client import get_daemon_client
183+
184+
daemon_client = get_daemon_client(profile.name)
185+
daemon_running = daemon_client.is_daemon_running
186+
187+
if daemon_running:
188+
echo.echo_warning('The daemon is currently running. It will need to be restarted for changes to take effect.')
189+
click.confirm('Do you want to apply the configuration and restart the daemon?', abort=True)
190+
164191
profile.set_process_controller(name='core.rabbitmq', config=broker_config)
165192
ctx.obj.config.update_profile(profile)
166193
ctx.obj.config.store()
167194

168195
echo.echo_success(f'RabbitMQ configuration for `{profile.name}` updated to: {broker_config}')
169196

197+
if daemon_running:
198+
echo.echo_report('Restarting the daemon...')
199+
daemon_client.restart_daemon()
200+
echo.echo_success('Daemon restarted successfully.')
201+
170202

171203
@verdi_profile.command('list')
172204
def profile_list():

src/aiida/cmdline/params/options/commands/setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,20 @@ def get_quicksetup_password(ctx: click.Context, param: click.Parameter, value: s
342342

343343
SETUP_USE_RABBITMQ = options.OverridableOption(
344344
'--use-rabbitmq/--no-use-rabbitmq',
345-
prompt='Use RabbitMQ?',
346345
is_flag=True,
347-
default=True,
346+
default=None,
347+
hidden=True,
348+
help='Deprecated: use --broker instead. --no-use-rabbitmq is equivalent to --broker none.',
349+
)
350+
351+
SETUP_BROKER_BACKEND = options.OverridableOption(
352+
'--broker',
353+
prompt='Message broker',
354+
type=click.Choice(['rabbitmq', 'zmq', 'none']),
355+
default='rabbitmq',
348356
cls=options.interactive.InteractiveOption,
349-
help='Whether to configure the RabbitMQ broker. Required to enable the daemon and submitting processes.',
357+
help='Message broker backend for process control. Use "rabbitmq" for RabbitMQ (requires external server), '
358+
'"zmq" for ZeroMQ (built-in, no external dependencies), or "none" to disable (limited functionality).',
350359
)
351360

352361
SETUP_BROKER_PROTOCOL = QUICKSETUP_BROKER_PROTOCOL.clone(

0 commit comments

Comments
 (0)