Crate lab_resource_manager

Crate lab_resource_manager 

Source
Expand description

§lab-resource-manager

GPU and room resource management system with Google Calendar and Slack integration.

This crate provides a resource management system designed for research labs, tracking GPU servers and meeting room reservations through Google Calendar and sending notifications via Slack.

§Architecture

Built with Clean Architecture (DDD + Hexagonal Architecture):

  • Domain Layer: Core business logic, aggregates, and value objects
  • Application Layer: Use cases that orchestrate domain logic
  • Infrastructure Layer: External system integrations (Google Calendar, Slack)

§Usage as a Binary

The primary use case is running the watcher service:

# Run with Google Calendar and Slack
cargo run --bin watcher

# Run with mock implementations for testing
cargo run --bin watcher --notifier mock --repository mock

# Customize polling interval (default: 60 seconds)
cargo run --bin watcher --interval 30

§Usage as a Library

You can also use this crate as a library to build custom resource management systems:

use lab_resource_manager::{
    NotifyResourceUsageChangesUseCase,
    GoogleCalendarUsageRepository,
    NotificationRouter,
    load_config,
};

// Load configuration
let config = load_config("config/resources.toml")?;

// Create repository and notifier
let repository = GoogleCalendarUsageRepository::new(
    "secrets/service-account.json",
    config.clone(),
).await?;
// NotificationRouter automatically supports all configured notification types
// (Slack, Mock, etc.) based on config/resources.toml
let notifier = NotificationRouter::new(config);

// Create and run use case
let usecase = NotifyResourceUsageChangesUseCase::new(repository, notifier).await?;
usecase.poll_once().await?;

§Device Specification Format

Calendar event titles support flexible device specification:

  • Single: 0 → Device 0
  • Range: 0-2 → Devices 0, 1, 2
  • Multiple: 0,2,5 → Devices 0, 2, 5
  • Mixed: 0-1,6-7 → Devices 0, 1, 6, 7

§Features

  • Google Calendar integration for resource reservations
  • Slack notifications for create/update/delete events
  • DDD Factory Pattern for device specification parsing
  • Mock implementations for testing
  • CLI arguments for flexible deployment

§Setup

See the README for detailed setup instructions.

Re-exports§

pub use application::error::ApplicationError;
pub use application::usecases::NotifyResourceUsageChangesUseCase;
pub use domain::ports::notifier::NotificationError;
pub use domain::ports::notifier::NotificationEvent;
pub use domain::ports::notifier::Notifier;
pub use domain::ports::repositories::RepositoryError;
pub use domain::ports::repositories::ResourceUsageRepository;
pub use infrastructure::config::load_config;
pub use infrastructure::notifier::router::NotificationRouter;
pub use infrastructure::notifier::senders::MockSender;
pub use infrastructure::notifier::senders::SlackSender;
pub use infrastructure::repositories::resource_usage::google_calendar::GoogleCalendarUsageRepository;
pub use infrastructure::repositories::resource_usage::mock::MockUsageRepository;

Modules§

application
Application Layer
domain
Domain Layer
infrastructure
Infrastructure Layer
prelude
Commonly used types for building resource management systems