@@ -37,10 +37,7 @@ public MinioDataClient(Configurations configurations, InformaticsGatewayConfigur
37
37
38
38
public async Task SendAsync ( DataProvider dataProvider , params object [ ] args )
39
39
{
40
- var minioClient = new MinioClient ( )
41
- . WithEndpoint ( _options . Storage . Settings [ "endpoint" ] )
42
- . WithCredentials ( _options . Storage . Settings [ "accessKey" ] , _options . Storage . Settings [ "accessToken" ] )
43
- . Build ( ) ;
40
+ var minioClient = CreateMinioClient ( ) ;
44
41
45
42
var stopwatch = new Stopwatch ( ) ;
46
43
stopwatch . Start ( ) ;
@@ -64,5 +61,33 @@ public async Task SendAsync(DataProvider dataProvider, params object[] args)
64
61
stopwatch . Stop ( ) ;
65
62
_outputHelper . WriteLine ( $ "Time to upload to Minio={ 0 } s...", stopwatch . Elapsed . TotalSeconds ) ;
66
63
}
64
+
65
+ private MinioClient CreateMinioClient ( ) => new MinioClient ( )
66
+ . WithEndpoint ( _options . Storage . Settings [ "endpoint" ] )
67
+ . WithCredentials ( _options . Storage . Settings [ "accessKey" ] , _options . Storage . Settings [ "accessToken" ] )
68
+ . Build ( ) ;
69
+
70
+ internal async Task CleanBucketAsync ( )
71
+ {
72
+ var stopwatch = new Stopwatch ( ) ;
73
+ stopwatch . Start ( ) ;
74
+ var minioClient = CreateMinioClient ( ) ;
75
+ var toBeRemoved = new List < string > ( ) ;
76
+ var listObjectArgs = new ListObjectsArgs ( )
77
+ . WithBucket ( _options . Storage . StorageServiceBucketName )
78
+ . WithRecursive ( true ) ;
79
+ var objects = minioClient . ListObjectsAsync ( listObjectArgs ) ;
80
+ objects . Subscribe ( ( item ) =>
81
+ {
82
+ toBeRemoved . Add ( item . Key ) ;
83
+ } ) ;
84
+ var deletObjectsArgs = new RemoveObjectsArgs ( )
85
+ . WithBucket ( _options . Storage . StorageServiceBucketName )
86
+ . WithObjects ( toBeRemoved ) ;
87
+ await minioClient . RemoveObjectsAsync ( deletObjectsArgs ) . ConfigureAwait ( false ) ;
88
+
89
+ stopwatch . Stop ( ) ;
90
+ _outputHelper . WriteLine ( $ "Cleaned up { 0 } objects from Minio in { 1 } s...", toBeRemoved . Count , stopwatch . Elapsed . TotalSeconds ) ;
91
+ }
67
92
}
68
93
}
0 commit comments