import { flow } from 'fp-ts/lib/function' ; import { ReindexSavedObject } from '../../../common/types' ; export interface SortedReindexSavedObjects { /**
     * Reindex objects sorted into this array represent Elasticsearch reindex tasks that
     * have no inherent order and are considered to be processed in parallel.
     */ parallel : ReindexSavedObject [ ] ; /**
     * Reindex objects sorted into this array represent Elasticsearch reindex tasks that
     * are consistently ordered (see  orderQueuedReindexOperations ) and should be
     * processed in order.
      queue : ReindexSavedObject [ ] ; } const sortReindexOperations = ( ops ) : SortedReindexSavedObjects => { const parallel = [ ] ; const queue = [ ] ; for ( const op of ops ) { if ( op . attributes . reindexOptions ?. queueSettings ) { queue . push ( op ) ; } else { parallel . push ( op ) ; } } return { parallel , queue , } ; } ; const orderQueuedReindexOperations = ( { parallel , queue , } ) : SortedReindexSavedObjects => ( { parallel , queue : queue . sort ( ( a , b ) => a . attributes . reindexOptions ! . queueSettings ! . queuedAt - b . attributes . reindexOptions ! . queueSettings ! . queuedAt ) , } ) ; export const isQueuedOp = ( op ) => Boolean ( op . attributes . reindexOptions ?. queueSettings ) ; export const queuedOpHasStarted = ( op ) => Boolean ( op . attributes . reindexOptions ?. queueSettings ?. startedAt ) ; export const sortAndOrderReindexOperations = flow ( sortReindexOperations , orderQueuedReindexOperations ) ;