@@ -43,40 +43,47 @@ fn async_runtime() -> tokio::runtime::Runtime {
43
43
. unwrap ( )
44
44
}
45
45
46
- pub async fn load_retention_from_global ( ) {
46
+ pub fn load_retention_from_global ( ) {
47
47
log:: info!( "loading retention for all streams" ) ;
48
- for stream in STREAM_INFO . list_streams ( ) {
49
- let res = CONFIG
50
- . storage ( )
51
- . get_object_store ( )
52
- . get_retention ( & stream)
53
- . await ;
54
- match res {
55
- Ok ( config) => {
56
- if config. tasks . is_empty ( ) {
57
- log:: info!( "skipping loading retention for {stream}" ) ;
58
- continue ;
59
- }
60
- init_scheduler ( & stream, config)
61
- }
62
- Err ( err) => log:: warn!( "failed to load retention config for {stream} due to {err:?}" ) ,
63
- }
64
- }
48
+ init_scheduler ( ) ;
65
49
}
66
50
67
- pub fn init_scheduler ( stream : & str , config : Retention ) {
68
- log:: info!( "Setting up schedular for {stream} " ) ;
51
+ pub fn init_scheduler ( ) {
52
+ log:: info!( "Setting up schedular" ) ;
69
53
let mut scheduler = AsyncScheduler :: new ( ) ;
70
- for Task { action, days, .. } in config. tasks . into_iter ( ) {
71
- let func = match action {
72
- Action :: Delete => {
73
- let stream = stream. to_string ( ) ;
74
- move || action:: delete ( stream. clone ( ) , u32:: from ( days) )
75
- }
76
- } ;
54
+ let func = move || async {
55
+ for stream in STREAM_INFO . list_streams ( ) {
56
+ let res = CONFIG
57
+ . storage ( )
58
+ . get_object_store ( )
59
+ . get_retention ( & stream)
60
+ . await ;
61
+
62
+ match res {
63
+ Ok ( config) => {
64
+ for Task { action, days, .. } in config. tasks . into_iter ( ) {
65
+ match action {
66
+ Action :: Delete => {
67
+ let stream = stream. to_string ( ) ;
68
+ thread:: spawn ( move || {
69
+ let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
70
+ rt. block_on ( async {
71
+ // Run the asynchronous delete action
72
+ action:: delete ( stream. clone ( ) , u32:: from ( days) ) . await ;
73
+ } ) ;
74
+ } ) ;
75
+ }
76
+ } ;
77
+ }
78
+ }
79
+ Err ( err) => {
80
+ log:: warn!( "failed to load retention config for {stream} due to {err:?}" )
81
+ }
82
+ } ;
83
+ }
84
+ } ;
77
85
78
- scheduler. every ( 1 . day ( ) ) . at ( "00:00" ) . run ( func) ;
79
- }
86
+ scheduler. every ( 1 . day ( ) ) . at ( "00:00" ) . run ( func) ;
80
87
81
88
let handler = thread:: spawn ( || {
82
89
let rt = async_runtime ( ) ;
@@ -183,7 +190,7 @@ mod action {
183
190
use crate :: option:: CONFIG ;
184
191
185
192
pub ( super ) async fn delete ( stream_name : String , days : u32 ) {
186
- log:: info!( "running retention task - delete" ) ;
193
+ log:: info!( "running retention task - delete for stream={stream_name} " ) ;
187
194
let retain_until = get_retain_until ( Utc :: now ( ) . date_naive ( ) , days as u64 ) ;
188
195
189
196
let Ok ( dates) = CONFIG
0 commit comments