@@ -2,10 +2,52 @@ use relay_config::Config;
22use relay_dynamic_config:: GlobalConfig ;
33#[ cfg( feature = "processing" ) ]
44use relay_dynamic_config:: { RetentionConfig , RetentionsConfig } ;
5+ #[ cfg( feature = "processing" ) ]
6+ use relay_system:: { Addr , FromMessage } ;
57
68use crate :: Envelope ;
79use crate :: managed:: { Managed , Rejected } ;
810use crate :: services:: projects:: project:: ProjectInfo ;
11+ #[ cfg( feature = "processing" ) ]
12+ use crate :: services:: store:: Store ;
13+ #[ cfg( feature = "processing" ) ]
14+ use crate :: services:: upload:: Upload ;
15+
16+ /// A transparent handle that dispatches between store-like services.
17+ #[ cfg( feature = "processing" ) ]
18+ #[ derive( Debug , Clone , Copy ) ]
19+ pub struct StoreHandle < ' a > {
20+ store : & ' a Addr < Store > ,
21+ upload : Option < & ' a Addr < Upload > > ,
22+ }
23+
24+ #[ cfg( feature = "processing" ) ]
25+ impl < ' a > StoreHandle < ' a > {
26+ pub fn new ( store : & ' a Addr < Store > , upload : Option < & ' a Addr < Upload > > ) -> Self {
27+ Self { store, upload }
28+ }
29+
30+ /// Sends a message to the [`Store`] service.
31+ pub fn store < M > ( & self , message : M )
32+ where
33+ Store : FromMessage < M > ,
34+ {
35+ self . store . send ( message) ;
36+ }
37+
38+ /// Sends a message to the [`Upload`] service.
39+ #[ expect( unused) ]
40+ pub fn upload < M > ( & self , message : M )
41+ where
42+ Upload : FromMessage < M > ,
43+ {
44+ if let Some ( upload) = self . upload {
45+ upload. send ( message) ;
46+ } else {
47+ relay_log:: error!( "Upload service not configured. Dropping message." ) ;
48+ }
49+ }
50+ }
951
1052/// A processor output which can be forwarded to a different destination.
1153pub trait Forward {
@@ -21,11 +63,8 @@ pub trait Forward {
2163 ///
2264 /// This function must only be called when Relay is configured to be in processing mode.
2365 #[ cfg( feature = "processing" ) ]
24- fn forward_store (
25- self ,
26- s : & relay_system:: Addr < crate :: services:: store:: Store > ,
27- ctx : ForwardContext < ' _ > ,
28- ) -> Result < ( ) , Rejected < ( ) > > ;
66+ fn forward_store ( self , s : StoreHandle < ' _ > , ctx : ForwardContext < ' _ > )
67+ -> Result < ( ) , Rejected < ( ) > > ;
2968}
3069
3170/// Context passed to [`Forward`].
@@ -80,11 +119,7 @@ impl Forward for Nothing {
80119 }
81120
82121 #[ cfg( feature = "processing" ) ]
83- fn forward_store (
84- self ,
85- _: & relay_system:: Addr < crate :: services:: store:: Store > ,
86- _: ForwardContext < ' _ > ,
87- ) -> Result < ( ) , Rejected < ( ) > > {
122+ fn forward_store ( self , _: StoreHandle < ' _ > , _: ForwardContext < ' _ > ) -> Result < ( ) , Rejected < ( ) > > {
88123 match self { }
89124 }
90125}
0 commit comments