session_cron_commands.py 1.6 KB

1234567891011121314151617181920212223242526272829
  1. """``/cron`` on the shared gateway: the classic CLI's handler (hermes_cli/cli_cron_lines.py), run by the owner.
  2. The profile's cron store belongs to the gateway whose ticker fires its jobs, so no client writes it. Bare
  3. ``/cron`` and ``list`` read, for every local session (main's TUI ran the same text in its slash worker). Every
  4. other form writes the store: it runs here when the classic CLI sends it on its own command socket, and a
  5. viewer's connection (Ink, Desktop, ACP) keeps main's refusal (gateway/session_commands.py).
  6. """
  7. from __future__ import annotations
  8. def cron_read(tokens):
  9. """``'overview'`` / ``'list'`` / ``'list-all'`` for the read forms of the shlex-split ``/cron`` argument;
  10. None for a write."""
  11. if not tokens:
  12. return 'overview'
  13. if tokens[0].lower() == 'list' and set(tokens[1:]) <= {'--all', '-a'}:
  14. return 'list-all' if tokens[1:] else 'list'
  15. return None
  16. async def run_cron(authority, arg) -> dict:
  17. """``/cron <arg>`` off the owner loop in the owning profile: the store is written here, never by a client."""
  18. from gateway.session_info_reads import owner_lines
  19. from hermes_cli.cli_cron_lines import cron_command_lines
  20. # A /cron run waits for its job, and the job's admission and execution take threads from the loop's
  21. # default pool (tracked_write, session_cron.execute). The wait therefore holds a thread of the runner's
  22. # unbounded turn pool, never one of the pool the job needs, however many runs (or Ctrl+C'd waits) pile up.
  23. return await owner_lines(authority, lambda: cron_command_lines(arg),
  24. getattr(authority.runner, '_run_in_executor_with_context', None))