Skip to content

Commit

Permalink
CLI: Add --most-recent-node option to verdi process watch
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Jun 6, 2024
1 parent 54ea4a6 commit c68b8e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/aiida/cmdline/commands/cmd_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,23 @@ def process_play(processes, all_entries, timeout, wait):

@verdi_process.command('watch')
@arguments.PROCESSES()
@options.MOST_RECENT_NODE()
@decorators.with_dbenv()
@decorators.with_broker
@decorators.only_if_daemon_running(echo.echo_warning, 'daemon is not running, so process may not be reachable')
def process_watch(broker, processes):
def process_watch(broker, processes, most_recent_node):
"""Watch the state transitions for a process."""

if not processes:
raise click.UsageError('Please specify one or multiple processes by their identifier (PK, UUID or label).')
if not processes and not most_recent_node:
raise click.UsageError(
'Please specify one or multiple processes by their identifier (PK, UUID or label) or use an option.'
)

if processes and most_recent_node:
raise click.BadOptionUsage(
'most_recent_node',
'cannot specify individual processes and the `-M/--most-recent-node` flag at the same time.',
)

from time import sleep

Expand All @@ -423,6 +432,9 @@ def _print(communicator, body, sender, subject, correlation_id):
communicator = broker.get_communicator()
echo.echo_report('watching for broadcasted messages, press CTRL+C to stop...')

if most_recent_node:
processes = [get_most_recent_node()]

for process in processes:
if process.is_terminated:
echo.echo_error(f'Process<{process.pk}> is already terminated')
Expand Down
6 changes: 6 additions & 0 deletions tests/cmdline/commands/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def test_process_watch(self, run_cli_command):
assert result.exit_code == ExitCode.USAGE_ERROR
assert len(result.output_lines) > 0

# Running with both identifiers should raise an error and print something
options = ['--most-recent-node', '1']
result = run_cli_command(cmd_process.process_watch, options, raises=True)
assert result.exit_code == ExitCode.USAGE_ERROR
assert len(result.output_lines) > 0

def test_process_status_call_link_label(self, run_cli_command):
"""Test ``verdi process status --call-link-label``."""
node = WorkflowNode().store()
Expand Down

0 comments on commit c68b8e7

Please sign in to comment.