Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dhall-configs/secrets/gtfs_in_memory_server_rust.dhall
# Temporary files
*.tmp
*.temp
CLAUDE.md
.claude/

# Unused files
ignored/
7 changes: 6 additions & 1 deletion assets/fleet_tag_list.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ chennai_bus,K5659,P6
chennai_bus,K5660,P7
chennai_bus,K5661,P8
chennai_bus,K5662,P10
chennai_bus,K5663,P9
chennai_bus,K5663,P9
kolkata_bus,K1001,P1
kolkata_bus,K1002,P2
kolkata_bus,K1003,P3
kolkata_bus,K1004,P4
kolkata_bus,K1005,P5
12 changes: 8 additions & 4 deletions assets/route_service_tiers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ kolkata_bus,sh1,PREMIUM
kolkata_bus,sh2,PREMIUM
kolkata_bus,sh3,PREMIUM
kolkata_bus,sh4,PREMIUM
kolkata_bus,1001,PREMIUM
kolkata_bus,1002,PREMIUM
kolkata_bus,1003,PREMIUM
kolkata_bus,1004,PREMIUM
kolkata_bus,1001,SHUTTLE
kolkata_bus,1002,SHUTTLE
kolkata_bus,1003,SHUTTLE
kolkata_bus,1004,SHUTTLE
kolkata_bus,1001033,SHUTTLE
kolkata_bus,1002033,SHUTTLE
kolkata_bus,1003033,SHUTTLE
kolkata_bus,1004033,SHUTTLE
12 changes: 11 additions & 1 deletion dhall-configs/dev/gtfs_in_memory_server_rust.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ let logger_cfg = {
log_to_file = False
}

let secrets = ../secrets/gtfs_in_memory_server_rust.example.dhall

in {
-- Logger configuration
logger_cfg = logger_cfg,
Expand Down Expand Up @@ -55,5 +57,13 @@ in {

-- Bhubaneswar vehicle cache configuration
bhubaneswar_cache_update_interval = 10,
phone_number_hash_key = "HASH_KEY"
phone_number_hash_key = "HASH_KEY",

enable_schedule_reconciliation=True,
-- OSRTC station cache configuration
osrtc_base_url = Some "OSRTC_BASE_URL",
osrtc_username = secrets.osrtc_username,
osrtc_secret_key = secrets.osrtc_secret_key,
osrtc_station_refresh_interval_hours = 1,
osrtc_feed_key = Some "odisha_osrtc"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
otp_url = "OTP_URL",
bhubaneswar_external_auth = Some "TEXT",
phone_number_hash_key = Some "TEXT",
enable_schedule_reconciliation = False
enable_schedule_reconciliation = False,
osrtc_username = Some "OSRTC_USERNAME",
osrtc_secret_key = Some "OSRTC_PASSWORD"
}
34 changes: 34 additions & 0 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::services::{
fleet_operator::{DBFleetOperatorService, FleetOperatorService, MockFleetOperatorService},
gtfs_service::GTFSService,
operator::{DBOperatorService, MockOperatorService, OperatorService},
osrtc_station_cache::OsrtcStationCache,
trip_service::TripService,
};
use crate::tools::dhall::read_dhall_config as dhall_read_config;
Expand Down Expand Up @@ -72,6 +73,11 @@ pub struct AppConfig {
pub phone_number_hash_key: String,
/// Enable schedule-based active trip reconciliation (default: false)
pub enable_schedule_reconciliation: bool,
pub osrtc_base_url: Option<String>,
pub osrtc_username: Option<String>,
pub osrtc_secret_key: Option<String>,
pub osrtc_station_refresh_interval_hours: u64,
pub osrtc_feed_key: Option<String>,
}

impl OtpConfig {
Expand Down Expand Up @@ -137,6 +143,7 @@ pub struct AppState {
pub fleet_operator_service: Arc<dyn FleetOperatorService>,
pub trip_service: Arc<TripService>,
pub chalo_vehicle_cache: Arc<ChaloVehicleCache>,
pub osrtc_cache: Option<Arc<OsrtcStationCache>>,
pub config: AppConfig,
pub bus_registration_mapping: Arc<HashMap<String, HashMap<String, String>>>,
pub fleet_list: Arc<HashMap<String, HashMap<String, Vec<String>>>>,
Expand Down Expand Up @@ -299,6 +306,32 @@ impl AppState {
chalo_vehicle_cache.set_update_interval(app_config.bhubaneswar_cache_update_interval);
let chalo_vehicle_cache = Arc::new(chalo_vehicle_cache);

let osrtc_cache = match (
&app_config.osrtc_base_url,
&app_config.osrtc_username,
&app_config.osrtc_secret_key,
) {
(Some(base_url), Some(username), Some(secret_key)) => {
let cache = OsrtcStationCache::new(
base_url.clone(),
username.clone(),
secret_key.clone(),
app_config.osrtc_station_refresh_interval_hours * 3600,
)?;
if let Err(e) = cache.initialize().await {
error!(
"OSRTC station cache initial load failed (will retry in background): {}",
e
);
}
Some(Arc::new(cache))
}
_ => {
info!("OSRTC credentials not configured; OSRTC station cache disabled");
None
}
};

// Load bus registration mapping from CSV
let bus_registration_mapping = Arc::new(Self::load_bus_registration_mapping().await?);

Expand All @@ -317,6 +350,7 @@ impl AppState {
fleet_operator_service,
trip_service,
chalo_vehicle_cache,
osrtc_cache,
config: app_config,
bus_registration_mapping,
fleet_list: Arc::new(Self::load_fleet_list().await?),
Expand Down
Loading