feat: crash recovery, service_failed monitoring, broker health fields, command expiry sweep
- Add GET /api/clients/crashed endpoint (process_status=crashed or stale heartbeat) - Add restart_app command action with same lifecycle + lockout as reboot_host - Scheduler: crash auto-recovery loop (CRASH_RECOVERY_ENABLED flag, lockout, MQTT publish) - Scheduler: unconditional command expiry sweep per poll cycle (sweep_expired_commands) - Listener: subscribe to infoscreen/+/service_failed; persist service_failed_at + unit - Listener: extract broker_connection block from health payload; persist reconnect_count + last_disconnect_at - DB migration b1c2d3e4f5a6: service_failed_at, service_failed_unit, mqtt_reconnect_count, mqtt_last_disconnect_at on clients - Add GET /api/clients/service_failed and POST /api/clients/<uuid>/clear_service_failed - Monitoring overview API: include mqtt_reconnect_count + mqtt_last_disconnect_at per client - Frontend: orange service-failed alert panel (hidden when empty, auto-refresh, quittieren action) - Frontend: MQTT reconnect count + last disconnect in client detail panel - MQTT auth hardening: listener/scheduler/server use env credentials; broker enforces allow_anonymous false - Client command lifecycle foundation: ClientCommand model, reboot_host/shutdown_host, full ACK lifecycle - Docs: TECH-CHANGELOG, DEV-CHANGELOG, MQTT_EVENT_PAYLOAD_GUIDE, copilot-instructions updated - Add implementation-plans/, RESTART_VALIDATION_CHECKLIST.md, TODO.md
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"""add client commands table
|
||||
|
||||
Revision ID: aa12bb34cc56
|
||||
Revises: f3c4d5e6a7b8
|
||||
Create Date: 2026-04-03 12:40:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'aa12bb34cc56'
|
||||
down_revision: Union[str, None] = 'f3c4d5e6a7b8'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
'client_commands',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('command_id', sa.String(length=36), nullable=False),
|
||||
sa.Column('client_uuid', sa.String(length=36), nullable=False),
|
||||
sa.Column('action', sa.String(length=32), nullable=False),
|
||||
sa.Column('status', sa.String(length=40), nullable=False),
|
||||
sa.Column('reason', sa.Text(), nullable=True),
|
||||
sa.Column('requested_by', sa.Integer(), nullable=True),
|
||||
sa.Column('issued_at', sa.TIMESTAMP(timezone=True), nullable=False),
|
||||
sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False),
|
||||
sa.Column('published_at', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('acked_at', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('execution_started_at', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('completed_at', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('failed_at', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column('error_code', sa.String(length=64), nullable=True),
|
||||
sa.Column('error_message', sa.Text(), nullable=True),
|
||||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.func.current_timestamp(), nullable=False),
|
||||
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.func.current_timestamp(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['client_uuid'], ['clients.uuid'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['requested_by'], ['users.id'], ondelete='SET NULL'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('command_id')
|
||||
)
|
||||
|
||||
op.create_index(op.f('ix_client_commands_action'), 'client_commands', ['action'], unique=False)
|
||||
op.create_index(op.f('ix_client_commands_client_uuid'), 'client_commands', ['client_uuid'], unique=False)
|
||||
op.create_index(op.f('ix_client_commands_command_id'), 'client_commands', ['command_id'], unique=False)
|
||||
op.create_index(op.f('ix_client_commands_requested_by'), 'client_commands', ['requested_by'], unique=False)
|
||||
op.create_index(op.f('ix_client_commands_status'), 'client_commands', ['status'], unique=False)
|
||||
op.create_index('ix_client_commands_client_status_created', 'client_commands', ['client_uuid', 'status', 'created_at'], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_client_commands_client_status_created', table_name='client_commands')
|
||||
op.drop_index(op.f('ix_client_commands_status'), table_name='client_commands')
|
||||
op.drop_index(op.f('ix_client_commands_requested_by'), table_name='client_commands')
|
||||
op.drop_index(op.f('ix_client_commands_command_id'), table_name='client_commands')
|
||||
op.drop_index(op.f('ix_client_commands_client_uuid'), table_name='client_commands')
|
||||
op.drop_index(op.f('ix_client_commands_action'), table_name='client_commands')
|
||||
op.drop_table('client_commands')
|
||||
Reference in New Issue
Block a user