@@ -16,9 +16,11 @@ use super::model::agent_secrets::{
1616 AgentSecretCreationRecord , AgentSecretExtRevisionRecord , AgentSecretRepoError ,
1717 AgentSecretRevisionRecord ,
1818} ;
19+ use super :: registry_change:: { RequiresNotificationSignal , RequiresSignalExt } ;
1920use crate :: repo:: model:: BindFields ;
2021pub use crate :: repo:: model:: account:: AccountRecord ;
2122use crate :: repo:: model:: agent_secrets:: AgentSecretRecord ;
23+ use crate :: repo:: registry_change:: { DbRegistryChangeRepo , NewRegistryChangeEvent } ;
2224use async_trait:: async_trait;
2325use conditional_trait_gen:: trait_gen;
2426use futures:: FutureExt ;
@@ -35,17 +37,17 @@ pub trait AgentSecretRepo: Send + Sync {
3537 async fn create (
3638 & self ,
3739 record : AgentSecretCreationRecord ,
38- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > ;
40+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError > ;
3941
4042 async fn update (
4143 & self ,
4244 revision : AgentSecretRevisionRecord ,
43- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > ;
45+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError > ;
4446
4547 async fn delete (
4648 & self ,
4749 revision : AgentSecretRevisionRecord ,
48- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > ;
50+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError > ;
4951
5052 async fn get_by_id (
5153 & self ,
@@ -83,23 +85,26 @@ impl<Repo: AgentSecretRepo> AgentSecretRepo for LoggedAgentSecretRepo<Repo> {
8385 async fn create (
8486 & self ,
8587 record : AgentSecretCreationRecord ,
86- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
88+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
89+ {
8790 let span = Self :: span_environment_id ( record. environment_id ) ;
8891 self . repo . create ( record) . instrument ( span) . await
8992 }
9093
9194 async fn update (
9295 & self ,
9396 revision : AgentSecretRevisionRecord ,
94- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
97+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
98+ {
9599 let span = Self :: span_agent_secret_id ( revision. agent_secret_id ) ;
96100 self . repo . update ( revision) . instrument ( span) . await
97101 }
98102
99103 async fn delete (
100104 & self ,
101105 revision : AgentSecretRevisionRecord ,
102- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
106+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
107+ {
103108 let span = Self :: span_agent_secret_id ( revision. agent_secret_id ) ;
104109 self . repo . delete ( revision) . instrument ( span) . await
105110 }
@@ -197,6 +202,9 @@ impl DbAgentSecretRepo<PostgresPool> {
197202
198203 let revision = Self :: insert_revision ( tx, record. revision ) . await ?;
199204
205+ let change_event = NewRegistryChangeEvent :: agent_secret_changed ( record. environment_id ) ;
206+ DbRegistryChangeRepo :: < PostgresPool > :: create_change_event_in_tx ( tx, & change_event) . await ?;
207+
200208 Ok ( AgentSecretExtRevisionRecord {
201209 environment_id : agent_secret_record. environment_id ,
202210 path : agent_secret_record. path ,
@@ -227,6 +235,10 @@ impl DbAgentSecretRepo<PostgresPool> {
227235 ) . await ?
228236 . ok_or ( AgentSecretRepoError :: ConcurrentModification ) ?;
229237
238+ let change_event =
239+ NewRegistryChangeEvent :: agent_secret_changed ( agent_secret_record. environment_id ) ;
240+ DbRegistryChangeRepo :: < PostgresPool > :: create_change_event_in_tx ( tx, & change_event) . await ?;
241+
230242 Ok ( AgentSecretExtRevisionRecord {
231243 environment_id : agent_secret_record. environment_id ,
232244 path : agent_secret_record. path ,
@@ -243,29 +255,34 @@ impl AgentSecretRepo for DbAgentSecretRepo<PostgresPool> {
243255 async fn create (
244256 & self ,
245257 record : AgentSecretCreationRecord ,
246- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
258+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
259+ {
247260 self . db_pool
248261 . with_tx_err ( METRICS_SVC_NAME , "create" , |tx| {
249262 Self :: create_within_transaction ( tx, record) . boxed ( )
250263 } )
251264 . await
265+ . map ( RequiresSignalExt :: requires_notification_signal)
252266 }
253267
254268 async fn update (
255269 & self ,
256270 revision : AgentSecretRevisionRecord ,
257- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
271+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
272+ {
258273 self . db_pool
259274 . with_tx_err ( METRICS_SVC_NAME , "update" , |tx| {
260275 Self :: update_within_transaction ( tx, revision) . boxed ( )
261276 } )
262277 . await
278+ . map ( RequiresSignalExt :: requires_notification_signal)
263279 }
264280
265281 async fn delete (
266282 & self ,
267283 revision : AgentSecretRevisionRecord ,
268- ) -> Result < AgentSecretExtRevisionRecord , AgentSecretRepoError > {
284+ ) -> Result < RequiresNotificationSignal < AgentSecretExtRevisionRecord > , AgentSecretRepoError >
285+ {
269286 self . db_pool . with_tx_err ( METRICS_SVC_NAME , "update" , |tx| {
270287 async move {
271288 let revision = Self :: insert_revision ( tx, revision. clone ( ) ) . await ?;
@@ -285,6 +302,12 @@ impl AgentSecretRepo for DbAgentSecretRepo<PostgresPool> {
285302 ) . await ?
286303 . ok_or ( AgentSecretRepoError :: ConcurrentModification ) ?;
287304
305+ let change_event = NewRegistryChangeEvent :: agent_secret_changed (
306+ agent_secret_record. environment_id ,
307+ ) ;
308+ DbRegistryChangeRepo :: < PostgresPool > :: create_change_event_in_tx ( tx, & change_event)
309+ . await ?;
310+
288311 Ok ( AgentSecretExtRevisionRecord {
289312 environment_id : agent_secret_record. environment_id ,
290313 path : agent_secret_record. path ,
@@ -293,7 +316,9 @@ impl AgentSecretRepo for DbAgentSecretRepo<PostgresPool> {
293316 revision
294317 } )
295318 } . boxed ( )
296- } ) . await
319+ } )
320+ . await
321+ . map ( RequiresSignalExt :: requires_notification_signal)
297322 }
298323
299324 async fn get_by_id (
0 commit comments