Skip to content

Issue 24: SDK Heartbeat Loop and State Machine #24

Description

@laraibg786

Goal

Build a background heartbeat scheduler with an internal state machine (ACTIVE, GRACE, EXPIRED, REVOKED) and callback hooks for state changes. The SDK manages the polling lifecycle; the host app registers callbacks.

Requirements

Functional

  • client.start_heartbeat(session_token, interval_seconds=300) → spawns background loop.
  • client.stop_heartbeat() → gracefully stops the loop.
  • State machine transitions: ACTIVEGRACEEXPIRED; REVOKED is terminal.
  • on_status_change(old_state, new_state, metadata) callback fired on every state transition.
  • on_error(exception) callback fired on unrecoverable heartbeat failure.
  • Retry up to 3 times on transient errors before calling on_error.

Technical

  • Threading: Use threading.Thread for sync; asyncio task for async.
  • Configurable interval: Default 5 minutes; demo mode supports 1 minute.
  • Graceful shutdown: Wait for in-flight heartbeat before stopping.

Acceptance Criteria

  • start_heartbeat() spawns background loop.
  • State transitions fire on_status_change callback.
  • stop_heartbeat() cleanly terminates the loop.
  • Error recovery retries 3 times before calling on_error.

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions