import * as Either from 'fp-ts/lib/Either' ; import * as TaskEither from 'fp-ts/lib/TaskEither' ; import { ElasticsearchClient } from '../../../elasticsearch' ; import { catchRetryableEsClientErrors , RetryableEsClientError , } from './catch_retryable_es_client_errors' ; internal export interface VerifyReindexParams { client : ElasticsearchClient ; sourceIndex : string ; targetIndex : string ; } export const verifyReindex = ( { client , sourceIndex , targetIndex , } ) : TaskEither . TaskEither < RetryableEsClientError | { type : 'verify_reindex_failed' ; } , 'verify_reindex_succeeded' > => ( ) => { const count = ( index ) => client . count < { count : number ; } > ( { index , allow_no_indices : false , } ) . then ( ( res ) => { return res . body . count ; } ) ; return Promise . all ( [ count ( sourceIndex ) , count ( targetIndex ) ] ) . then ( ( [ sourceCount , targetCount ] ) => { if ( targetCount >= sourceCount ) { return Either . right ( 'verify_reindex_succeeded' as const ) ; } else { return Either . left ( { type : 'verify_reindex_failed' as const } ) ; } } ) . catch ( catchRetryableEsClientErrors ) ; } ;