mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
Renames (no functional change, just consistency with the rest of the codebase): - cli/cli_utils.py → cli/cli_util.py - core/host_utils.py → core/host_util.py - core/tag_utils.py → core/tag_util.py - crawls/schedule_utils.py → crawls/schedule_util.py - machine/env_utils.py → machine/env_util.py Functional fixes: - archivebox add --index-only now materializes Snapshot rows synchronously via crawl.create_snapshots_from_urls() instead of just queueing the Crawl and leaving the index empty. The previous behavior broke every test that expected --index-only to populate the index, since the runner is never started in index-only mode. - config/collection.py: add _coerce_from_str_dict as the inverse of _coerce_to_str_dict so JSON-encoded INI values are decoded back to native dict/list types when mirrored into Machine.config (a JSONField). Without this, downstream consumers like MachineEvent / abx-dl get raw JSON strings where they expect dicts. Plus matching admin / middleware / model touch-ups, the registration password_change_form template, and assorted small cleanups the user worked through while validating the deploy path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
111 lines
3.0 KiB
Python
111 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
archivebox process <action> [--filters]
|
|
|
|
Manage Process records (system-managed, mostly read-only).
|
|
|
|
Process records track executions of binaries during extraction.
|
|
They are created automatically by the system and are primarily for debugging.
|
|
|
|
Actions:
|
|
list - List Processes as JSONL (with optional filters)
|
|
|
|
Examples:
|
|
# List all processes
|
|
archivebox process list
|
|
|
|
# List processes by binary
|
|
archivebox process list --binary-name=chrome
|
|
|
|
# List recent processes
|
|
archivebox process list --limit=10
|
|
"""
|
|
|
|
__package__ = "archivebox.cli"
|
|
__command__ = "archivebox process"
|
|
|
|
import sys
|
|
|
|
import rich_click as click
|
|
from rich import print as rprint
|
|
|
|
from archivebox.cli.cli_util import apply_filters
|
|
|
|
|
|
# =============================================================================
|
|
# LIST
|
|
# =============================================================================
|
|
|
|
|
|
def list_processes(
|
|
binary_name: str | None = None,
|
|
machine_id: str | None = None,
|
|
limit: int | None = None,
|
|
) -> int:
|
|
"""
|
|
List Processes as JSONL with optional filters.
|
|
|
|
Exit codes:
|
|
0: Success (even if no results)
|
|
"""
|
|
from archivebox.misc.jsonl import write_record
|
|
from archivebox.machine.models import Process
|
|
|
|
is_tty = sys.stdout.isatty()
|
|
|
|
queryset = Process.objects.all().select_related("binary", "machine").order_by("-started_at", "-created_at")
|
|
|
|
# Apply filters
|
|
filter_kwargs = {}
|
|
if binary_name:
|
|
filter_kwargs["binary__name"] = binary_name
|
|
if machine_id:
|
|
filter_kwargs["machine_id"] = machine_id
|
|
|
|
queryset = apply_filters(queryset, filter_kwargs, limit=limit)
|
|
|
|
count = 0
|
|
for process in queryset:
|
|
if is_tty:
|
|
binary_name_str = process.binary.name if process.binary else "unknown"
|
|
exit_code = process.exit_code if process.exit_code is not None else "?"
|
|
status_color = "green" if process.exit_code == 0 else "red" if process.exit_code else "yellow"
|
|
rprint(f"[{status_color}]exit={exit_code:3}[/{status_color}] [cyan]{binary_name_str:15}[/cyan] [dim]{process.id}[/dim]")
|
|
else:
|
|
write_record(process.to_json())
|
|
count += 1
|
|
|
|
rprint(f"[dim]Listed {count} processes[/dim]", file=sys.stderr)
|
|
return 0
|
|
|
|
|
|
# =============================================================================
|
|
# CLI Commands
|
|
# =============================================================================
|
|
|
|
|
|
@click.group()
|
|
def main():
|
|
"""Manage Process records (read-only, system-managed)."""
|
|
pass
|
|
|
|
|
|
@main.command("list")
|
|
@click.option("--binary-name", "-b", help="Filter by binary name")
|
|
@click.option("--machine-id", "-m", help="Filter by machine ID")
|
|
@click.option("--limit", "-n", type=int, help="Limit number of results")
|
|
def list_cmd(binary_name: str | None, machine_id: str | None, limit: int | None):
|
|
"""List Processes as JSONL."""
|
|
sys.exit(
|
|
list_processes(
|
|
binary_name=binary_name,
|
|
machine_id=machine_id,
|
|
limit=limit,
|
|
),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|