Skip to content

Conversation

@apo-mak
Copy link
Contributor

@apo-mak apo-mak commented Dec 8, 2025

This pull request introduces a new background cleanup feature to automatically remove stale or incomplete node records from the database.
Based on this : #473

The feature is configurable via environment variables and is disabled by default. Key changes include the addition of the Cleanup module, configuration options for cleanup scheduling and criteria, and integration of the cleanup process into the application lifecycle.

Background node cleanup feature:

  • Added the new Cleanup module (web/lib/potato_mesh/application/cleanup.rb) that provides methods to prune stale nodes, run cleanup cycles, and manage a background cleanup thread. Stale nodes are defined as those with default names and missing hardware model info, and older than a configurable minimum age.

Configuration and environment variables:

  • Introduced two new environment variables in README.md: STALE_NODE_CLEANUP_INTERVAL (hours between cleanup cycles, default disabled) and STALE_NODE_MIN_AGE (minimum node age in hours before cleanup, default 168).
  • Added configuration logic in Config to handle cleanup interval and minimum age, including helper methods for conversion and validation. [1] [2]

Integration with application lifecycle:

  • Registered and included the Cleanup module in the main application class to ensure its methods are available and its thread is managed alongside other core features. [1] [2] [3] [4]
  • Added logic to start or skip the cleanup thread during application startup based on configuration, and to manage the thread's lifecycle. [1] [2]

Copilot AI review requested due to automatic review settings December 8, 2025 13:48
@apo-mak apo-mak marked this pull request as draft December 8, 2025 13:51
Copy link
Contributor

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.

Pull request overview

This PR introduces a configurable background cleanup feature to automatically remove incomplete/stale node records from the database. The implementation adds a new Cleanup module that identifies and removes nodes with default Meshtastic names and missing hardware information after a configurable minimum age. The feature is disabled by default and can be enabled via the STALE_NODE_CLEANUP_INTERVAL environment variable.

Key changes:

  • Added Cleanup module with automatic stale node removal based on configurable age and interval
  • Introduced two environment variables: STALE_NODE_CLEANUP_INTERVAL (default: 0/disabled) and STALE_NODE_MIN_AGE (default: 168 hours)
  • Integrated cleanup thread lifecycle management into the main application startup

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
web/lib/potato_mesh/application/cleanup.rb New module implementing stale node detection and cleanup logic with background thread management
web/lib/potato_mesh/config.rb Added configuration methods for cleanup interval and minimum age with environment variable parsing
web/lib/potato_mesh/application.rb Integrated Cleanup module and thread startup into application lifecycle
README.md Documented new environment variables with defaults and usage examples
web/spec/cleanup_spec.rb Comprehensive test coverage for cleanup functionality and configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@l5yth
Copy link
Owner

l5yth commented Dec 8, 2025

How do you determine a stale node though?

@apo-mak
Copy link
Contributor Author

apo-mak commented Dec 8, 2025

How do you determine a stale node though?

i use the logic that was suggested here : #473
DELETE FROM nodes WHERE long_name LIKE 'Meshtastic%' AND (hw_model IS NULL OR hw_model = '');

and I leave it up to the admin to decide the appropriate time frame for stale consideration.

@l5yth
Copy link
Owner

l5yth commented Dec 16, 2025

I'll review this for the next release

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.

2 participants