Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 6, 2025

Overview

Adds a new aignostics system online CLI command to check network connectivity with intelligent caching to minimize unnecessary network requests.

Changes

CLI Command

Added aignostics system online command that:

  • Returns exit code 0 when online (success)
  • Returns exit code 1 when offline (failure)
  • Displays green message "System is online" when connected
  • Displays red message "System is not online" when disconnected

Service Method

Implemented is_online() method in the system service that:

  • Leverages existing _determine_network_health() infrastructure
  • Checks connectivity to https://api.ipify.org (reliable, well-known endpoint)
  • Returns boolean indicating online status

Smart Caching

Implemented efficient caching mechanism to avoid excessive network checks:

  • Default TTL: 60 seconds
  • Configurable via AIGNOSTICS_SYSTEM_ONLINE_CACHE_TTL_SECONDS environment variable
  • Minimum value: 0 (disables caching for always-fresh checks)
  • Cache stores result and timestamp as tuple for minimal memory footprint

Tests

Added comprehensive test coverage:

  • 6 service tests covering cache behavior, TTL expiration, and configuration
  • 2 CLI tests validating exit codes and output for both online and offline scenarios

Usage

Basic check

aignostics system online
# Output: System is online (in green)
# Exit code: 0

Custom cache TTL

export AIGNOSTICS_SYSTEM_ONLINE_CACHE_TTL_SECONDS=30
aignostics system online

Disable caching

export AIGNOSTICS_SYSTEM_ONLINE_CACHE_TTL_SECONDS=0
aignostics system online  # Always checks network

In shell scripts

#!/bin/bash
if aignostics system online; then
    echo "Connected! Proceeding with online operations..."
    # Perform online operations
else
    echo "Offline. Cannot proceed."
    exit 1
fi

Technical Details

  • Cache implementation: Simple tuple (is_online, timestamp) stored at class level
  • Network check: Uses existing _determine_network_health() method with 5-second timeout
  • Thread-safety: Not required (CLI operations are single-threaded per invocation)
  • Logging: Debug-level logs for cache hits/misses to aid troubleshooting

Design Decisions

  1. Reused existing infrastructure: Leverages _determine_network_health() which already checks api.ipify.org
  2. Minimal changes: Only 178 lines added across 5 files
  3. Unix conventions: Exit codes follow standard conventions (0=success, non-zero=failure)
  4. Color-coded output: Uses existing console styles for consistency
  5. Configurable defaults: 60-second cache balances freshness with efficiency

Files Modified

  • src/aignostics/system/_settings.py (+9 lines) - Added online_cache_ttl_seconds setting
  • src/aignostics/system/_service.py (+31 lines) - Implemented is_online() with caching
  • src/aignostics/system/_cli.py (+16 lines) - Added online CLI command
  • tests/aignostics/system/service_test.py (+106 lines) - Service tests
  • tests/aignostics/system/cli_test.py (+16 lines) - CLI tests

Closes #[issue-number]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>PR with online detection</issue_title>
<issue_description>Add CLI command "aignostics system online" which exits with 1 if not online, 0 otherwise, and prints info if online (green) or not (red).

For that provide is_online() in system service, drawing from system info, as in using well known and reliable source to check connectivity.

Cache online information for 60 seconds (default), with that number configurable in settings of system module.

Provide tests for the above in tests directory of system module.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #151

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

- Add online_cache_ttl_seconds setting (default 60s) to system settings
- Implement is_online() method in Service class with 60-second cache
- Add "aignostics system online" CLI command with exit codes (0=online, 1=offline)
- Add comprehensive tests for is_online() including cache behavior
- Add tests for CLI online command

Co-authored-by: helmut-hoffer-von-ankershoffen <[email protected]>
@Copilot Copilot AI changed the title [WIP] PR with online detection Add online detection CLI command with configurable caching Oct 6, 2025
Copilot finished work on behalf of helmut-hoffer-von-ankershoffen October 6, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PR with online detection
2 participants