hypercall/runtime/
api_service_adapters.rs1use std::sync::Arc;
2
3use crate::shared::service::{Service, ServiceOwner};
4use crate::shared::ShutdownRx;
5use hypercall_api::caches::{
6 CompetitionsSnapshotCache, InstrumentsSnapshotCache, MarketsSnapshotCache,
7 OptionsSummarySnapshotCache, SparklinesSnapshotCache,
8};
9use hypercall_api::candles::CandleWsPublisher;
10use hypercall_api::upstash::UpstashBatchPublisher;
11
12macro_rules! snapshot_service_impl {
13 ($ty:ty, $name:literal) => {
14 #[async_trait::async_trait]
15 impl Service for $ty {
16 fn name(&self) -> &'static str {
17 $name
18 }
19
20 fn owner(&self) -> ServiceOwner {
21 ServiceOwner::Api
22 }
23
24 async fn run(self: Arc<Self>, shutdown: ShutdownRx) -> anyhow::Result<()> {
25 self.start_with_shutdown(shutdown)
26 .await
27 .map_err(|e| anyhow::anyhow!("{} task failed: {:?}", $name, e))
28 }
29 }
30 };
31}
32
33snapshot_service_impl!(InstrumentsSnapshotCache, "InstrumentsSnapshotCache");
34snapshot_service_impl!(MarketsSnapshotCache, "MarketsSnapshotCache");
35snapshot_service_impl!(SparklinesSnapshotCache, "SparklinesSnapshotCache");
36snapshot_service_impl!(CompetitionsSnapshotCache, "CompetitionsSnapshotCache");
37snapshot_service_impl!(OptionsSummarySnapshotCache, "OptionsSummarySnapshotCache");
38
39#[async_trait::async_trait]
40impl Service for CandleWsPublisher {
41 fn name(&self) -> &'static str {
42 "CandleWsPublisher"
43 }
44
45 fn owner(&self) -> ServiceOwner {
46 ServiceOwner::Api
47 }
48
49 async fn run(self: Arc<Self>, shutdown: ShutdownRx) -> anyhow::Result<()> {
50 self.run_with_shutdown(shutdown).await;
51 Ok(())
52 }
53}
54
55#[async_trait::async_trait]
56impl Service for UpstashBatchPublisher {
57 fn name(&self) -> &'static str {
58 "UpstashBatchPublisher"
59 }
60
61 fn owner(&self) -> ServiceOwner {
62 ServiceOwner::Api
63 }
64
65 async fn run(self: Arc<Self>, shutdown: ShutdownRx) -> anyhow::Result<()> {
66 self.run_with_shutdown(shutdown).await
67 }
68}