<div dir="ltr">It's a step removed from that, and `seq`'ing insertData isn't fixing it, only a threadDelay is.<div><br></div><div>The operations insertData is performing are:</div><div>delete index, create index, add document to index</div>
<div><br></div><div>the operation queryTweet is performing is:</div><div>search index</div><div><br></div><div>The behavior seems to indicate "search index" is happening before "add document to index" and after "delete index", as the document will not exist when the query is performed.</div>
<div><br></div><div>Only adding a threadDelay as reliably worked. Even `seq`'ing insertData doesn't work.</div><div><br></div><div>Are the requests somehow being performed concurrently?</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 1:15 AM, Michael Snoyman <span dir="ltr"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I can't say I fully understand your code, but it seems like it's doing the following:<div><br></div><div>1. Send request to server to delete data.</div><div>2. Send request to server to add data.</div>


<div>3. Request data from server.</div><div><br></div><div>You're saying that with a long enough delay between steps 2 and 3, then (3) works, otherwise it fails. It sounds to me like there's some kind of a race condition. I don't know anything about createExampleIndex, but are you certain that it only returns after the data is completely ready for querying?</div>


</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, Apr 10, 2014 at 8:43 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">to add to my question adding a delay made it work:<div><br></div><div>
<div><div>main :: IO ()</div>

<div>main = do</div><div>  _ <- insertData</div></div><div>  threadDelay 1000000</div><div><div>  myTweet <- queryTweet</div>
<div>  print myTweet</div></div></div><div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 12:41 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Repro'd on GHC 7.8.1 and 7.6.3</div><div><br></div>Original code is: <a href="https://github.com/bitemyapp/bloodhound/" target="_blank">https://github.com/bitemyapp/bloodhound/</a><br>



<br>The code only works if I manually (out of band) run insertData (in a REPL) and then run main with the insertData invocation stripped out. If I run main with the insertData invocation included, it throws an exception (head) because the search results are empty.<div>




<br>The behavior is as if queryTweet was executing after insertData deleted the index, but before it inserted the new data.<br><br>The following is a stripped down example:<br><br>insertData :: IO ()<br>insertData = do<br>




  let encoded = encode exampleTweet<br>  _ <- deleteExampleIndex<br>  created <- createExampleIndex<br>  docCreated <- indexDocument (Server "<a href="http://localhost:9200" target="_blank">http://localhost:9200</a>") "twitter" "tweet" exampleTweet "1"<br>




  print "test"<br>  return ()<br>el<br>queryTweet :: IO (Either String Tweet)<br>queryTweet = do<br>  let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)<br>                    <||> IdentityFilter<br>




  let search = Search Nothing (Just queryFilter)<br>  reply <- searchByIndex testServer "twitter" search<br>  let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)<br>  let myTweet = fmap (hitSource . head . hits . searchHits) result<br>




  return myTweet<br><br>main :: IO ()<br>main = do<br>  _ <- insertData<br>  myTweet <- queryTweet<br>  print myTweet</div><div><br></div><div>further up the call chain, the http call is getting dispatched with http-conduit's gear, the result returned with the expression:</div>




<div><br></div><div>withManager $ httpLbs req<br></div><div><br></div><div>Included this in case it affects the semantics.</div><div><br></div><div>Can anybody help? This has stumped me for a couple hours and I couldn't get anything clueful on IRC.<br>




</div><div><br></div><div>Thanks to any that help.</div><div><br></div><div>--- Chris</div><div><br></div></div>
</blockquote></div><br></div>
</div></div><br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>