extract background tasks into worker binary

Move auto_scheduler, library_sync, broadcast_poller, webhook_consumer
from presentation/background/ into crates/worker/src/jobs/.
Presentation is now a pure HTTP server.
This commit is contained in:
2026-07-12 07:28:17 +02:00
parent 826e824b58
commit abcf69ce7e
13 changed files with 521 additions and 48 deletions

View File

@@ -33,9 +33,7 @@ pub async fn build_app_state(config: Config) -> anyhow::Result<AppState> {
DbPool::Sqlite(p) => p.clone(),
};
let event_publisher: Arc<dyn domain::ports::EventPublisher> =
Arc::new(adapter_event_publisher::SqliteEventPublisher::new(sqlite_pool.clone()));
let event_consumer: Arc<dyn domain::ports::EventConsumer> =
Arc::new(adapter_event_publisher::SqliteEventConsumer::new(sqlite_pool));
Arc::new(adapter_event_publisher::SqliteEventPublisher::new(sqlite_pool));
let provider_registry = build_provider_registry(&config).await;
@@ -62,8 +60,6 @@ pub async fn build_app_state(config: Config) -> anyhow::Result<AppState> {
Arc::new(adapter_auth::JwtTokenService::new(validator))
};
let (sync_tx, sync_rx) = tokio::sync::watch::channel(());
let auth_deps = Arc::new(AuthDeps {
user_command: wire_output.user_command.clone(),
user_query: wire_output.user_query.clone(),
@@ -129,34 +125,6 @@ pub async fn build_app_state(config: Config) -> anyhow::Result<AppState> {
let config_arc = Arc::new(config);
let bg_schedule_deps = schedule_deps.clone();
tokio::spawn(crate::background::auto_scheduler::run(bg_schedule_deps));
let bg_schedule_deps2 = schedule_deps.clone();
let bg_event_publisher = event_publisher.clone();
tokio::spawn(crate::background::broadcast_poller::run(
bg_schedule_deps2,
bg_event_publisher,
));
let webhook_consumer = event_consumer.clone();
let webhook_channel_query = wire_output.channel_query.clone();
tokio::spawn(crate::background::webhook_consumer::run(
webhook_consumer,
webhook_channel_query,
reqwest::Client::new(),
));
let bg_sync = library_sync.clone();
let bg_registry = provider_registry.clone();
let bg_settings = wire_output.settings.clone();
tokio::spawn(crate::background::library_sync::run(
bg_sync,
bg_registry,
bg_settings,
sync_rx,
));
Ok(AppState {
auth_deps,
channel_command_deps,
@@ -176,11 +144,7 @@ pub async fn build_app_state(config: Config) -> anyhow::Result<AppState> {
provider_config_command: wire_output.provider_config_command.clone(),
#[cfg(feature = "auth-jwt")]
jwt_validator,
_library_sync: library_sync,
_event_publisher: event_publisher,
_event_consumer: event_consumer,
config: config_arc,
_sync_trigger: sync_tx,
})
}