66using System . Threading ;
77using McMaster . Extensions . CommandLineUtils ;
88using osu . Server . QueueProcessor ;
9+ using StackExchange . Redis ;
910
1011namespace osu . ElasticIndexer . Commands . Index
1112{
1213 [ Command ( "close" , Description = "Closes unused indices." ) ]
13- public class CloseIndexCommand : ListIndicesCommand
14+ public class CloseIndexCommand
1415 {
1516 [ Argument ( 0 , "name" , "The index to close. All unused indices are closed if not specified." ) ]
1617 public string ? Name { get ; set ; }
1718
18- public override int OnExecute ( CancellationToken token )
19- {
20- if ( base . OnExecute ( token ) != 0 )
21- return - 1 ;
19+ private readonly ConnectionMultiplexer redis = RedisAccess . GetConnection ( ) ;
20+ private readonly OsuElasticClient elasticClient = new OsuElasticClient ( ) ;
2221
23- var indices = string . IsNullOrEmpty ( Name ) ? ElasticClient . GetIndices ( $ "{ AppSettings . AliasName } _*") : ElasticClient . GetIndex ( Name ) ;
22+ public int OnExecute ( CancellationToken token )
23+ {
24+ var indices = string . IsNullOrEmpty ( Name ) ? elasticClient . GetIndices ( $ "{ AppSettings . AliasName } _*") : elasticClient . GetIndex ( Name ) ;
2425
2526 var closeableIndices = indices . Where ( entry => entry . Value . Aliases . Count == 0 ) ;
2627
@@ -47,17 +48,17 @@ public override int OnExecute(CancellationToken token)
4748
4849 foreach ( var entry in closeableIndices )
4950 {
50- if ( entry . Key . Name == Redis . GetCurrentSchema ( ) )
51+ if ( entry . Key . Name == redis . GetCurrentSchema ( ) )
5152 {
5253 Console . WriteLine ( ConsoleColor . Red , $ "Index { entry . Key . Name } is set as current schema. Cannot close.") ;
5354 return - 1 ;
5455 }
5556
5657 System . Console . WriteLine ( $ "Removing { entry . Key . Name } from active schemas..") ;
57- Redis . RemoveActiveSchema ( entry . Key . Name ) ;
58+ redis . RemoveActiveSchema ( entry . Key . Name ) ;
5859
5960 Console . WriteLine ( $ "Closing { entry . Key . Name } ...") ;
60- var response = ElasticClient . Indices . Close ( entry . Key . Name ) ;
61+ var response = elasticClient . Indices . Close ( entry . Key . Name ) ;
6162
6263 if ( ! response . IsValid )
6364 {
@@ -68,7 +69,7 @@ public override int OnExecute(CancellationToken token)
6869
6970 Console . WriteLine ( "done." ) ;
7071
71- return 0 ;
72+ return ListIndicesCommand . ListSchemas ( redis , elasticClient ) ;
7273 }
7374 }
7475}
0 commit comments