Module StartWatcher

Module StartWatcher 

Source
Expand description

§StartWatcher

§File: Indexing/Background/StartWatcher.rs

§Role in Air Architecture

Provides background task management for the File Indexer service, handling file watching startup and periodic indexing tasks.

§Primary Responsibility

Start and manage background file watcher and periodic indexing tasks for the indexing service.

§Secondary Responsibilities

  • File watcher initialization and lifecycle management
  • Periodic background re-indexing
  • Watcher event debouncing
  • Background task cleanup

§Dependencies

External Crates:

  • notify - File system watching
  • tokio - Async runtime for background tasks

Internal Modules:

  • crate::Result - Error handling type
  • crate::AirError - Error types
  • crate::ApplicationState::ApplicationState - Application state
  • super::super::FileIndexer - Main file indexer
  • super::WatchFile - File watching operations

§Dependents

  • Indexing::mod::FileIndexer - Main file indexer implementation

§VSCode Pattern Reference

Inspired by VSCode’s background services in src/vs/workbench/services/search/common/

§Security Considerations

  • Path validation before watching
  • Watch path limits enforcement
  • Permission checking on watch paths

§Performance Considerations

  • Event debouncing prevents excessive re-indexing
  • Parallel processing of file changes
  • Efficient background task scheduling

§Error Handling Strategy

Background tasks log errors and continue running, ensuring temporary failures don’t stop the indexing service.

§Thread Safety

Background tasks use Arc for shared state and async/await for safe concurrent operations.

Structs§

BackgroundIndexerContext
Background indexer context containing shared state
WatcherStatus
Watcher status information

Functions§

GetWatcherStatus
Get watcher status
StartAll
Start all background components (watcher and tasks)
StartBackgroundTasks
Start background tasks for periodic indexing
StartDebounceProcessor
Start the debounce processor task
StartFileWatcher
Start file watcher for incremental indexing
StopAll
Stop all background components
StopBackgroundTasks
Stop background tasks
StopFileWatcher
Stop file watcher