git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #151 from andrewthad/index_status_check

add function for checking index status

commit8930ea1b4431161bb4276f8c3ceb8670bb1071d4 authorChris Allen <cma@bitemyapp.com> dateThu 3 Nov 2016, 17:03 (10 years ago) parentf43b776cb915c7
1 file changed+9
src/Database/Bloodhound/Client.hs+9
src/Database/Bloodhound/Client.hs+9
@@ -33,6 +33,7 @@ module Database.Bloodhound.Client
3333 , openIndex
3434 , closeIndex
3535 , listIndices
36+ , waitForYellowIndex
3637 -- *** Index Aliases
3738 , updateIndexAliases
3839 , getIndexAliases
@@ -633,6 +634,14 @@ refreshIndex (IndexName indexName) =
633634 bindM2 post url (return Nothing)
634635 where url = joinPath [indexName, "_refresh"]
635636
637+-- | Block until the index becomes available for indexing
638+-- documents. This is useful for integration tests in which
639+-- indices are rapidly created and deleted.
640+waitForYellowIndex :: MonadBH m => IndexName -> m Reply
641+waitForYellowIndex (IndexName indexName) = get =<< url
642+ where url = addQuery q <$> joinPath ["_cluster","health",indexName]
643+ q = [("wait_for_status",Just "yellow"),("timeout",Just "10s")]
644+
636645stringifyOCIndex :: OpenCloseIndex -> Text
637646stringifyOCIndex oci = case oci of
638647 OpenIndex -> "_open"