public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/ag:master commit in: lib/
Date: Tue, 24 Feb 2015 03:39:50 +0000 (UTC)	[thread overview]
Message-ID: <1424749184.51aea5a8f68dc5d4a49e6795ff83d439c7f03942.robbat2@gentoo> (raw)

commit:     51aea5a8f68dc5d4a49e6795ff83d439c7f03942
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 24 03:39:44 2015 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Tue Feb 24 03:39:44 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=51aea5a8

Working index status check!

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

---
 lib/storage.rb | 37 +++++++++++--------------------------
 1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/lib/storage.rb b/lib/storage.rb
index 7ec0861..4135971 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -5,28 +5,25 @@ require 'pp'
 module Ag::Storage
   module_function
 
-  def index_states(indexname)
-    status = $es.indices.status(index: indexname)
-    states = status['indices'][indexname]['shards'].map do |key,array|
-      array.map do |v|
-          v['routing']['state']
-      end.flatten
-    end.flatten
+  def index_status(indexname)
+    $es.cluster.health(level: :indices)['indices'][indexname]['status']
   end
+
   def index_ready?(indexname)
-    states = index_states(indexname)
-    not_ready = states.include? 'INITIALIZING' or states.include? 'RELOCATING'
-    return !not_ready
-    pp $es.cluster.health(level: indices)
+    status = index_status(indexname) 
+    # if you call index_status twice, you might get different results!
+    return status == 'green' or status == 'yellow'
   end
 
   # Throws Elasticsearch::Transport::Transport::Errors::NotFound
   # if the list does not exist
   def delete_index(list)
-      $es.indices.delete index: 'ml-' + list
+      $es.indices.delete(index: 'ml-' + list)
   end
 
-  def create_index(list)
+  # Create an index for list
+  # sleep in 5ms intervals until it is ready
+  def create_index(list, sleeptime: 0.005)
     indexname = 'ml-' + list
     $es.indices.create(
       index: indexname,
@@ -103,20 +100,8 @@ module Ag::Storage
         }
       })
 
-    pp $es.cluster.health(level: indices)
     # Give elasticsearch some time to process the new index
-    status = $es.indices.status(index: indexname)
-    while $es.cluster.health['status'] != 'green' do
-      pp status
-      pp status['indices'][indexname]['shards']
-      status = status['indices'][indexname]['shards'].map do |k,v|
-        v[0]['routing']['state']
-      end
-      pp status
-      sleep 0.01
-      status = $es.indices.status(index: indexname)
-    end
-    pp $es.indices.status(index: indexname)
+    sleep sleeptime while not index_ready?(indexname)
   end
 
   def get_content(message, filename)


             reply	other threads:[~2015-02-24  3:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-24  3:39 Robin H. Johnson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-29 19:45 [gentoo-commits] proj/ag:master commit in: lib/ Alex Legler
2015-03-07 21:13 Alex Legler
2015-03-07 21:11 Alex Legler
2015-02-25 10:31 Alex Legler
2015-02-24  3:42 Robin H. Johnson
2015-02-24  3:32 Robin H. Johnson
2015-02-24  3:19 Robin H. Johnson
2015-02-24  3:16 Robin H. Johnson
2015-02-24  3:08 Robin H. Johnson
2015-02-24  3:06 Robin H. Johnson
2015-02-24  3:02 Robin H. Johnson
2015-02-24  2:59 Robin H. Johnson
2015-02-24  2:57 Robin H. Johnson
2015-02-24  2:55 Robin H. Johnson
2015-02-24  2:53 Robin H. Johnson
2015-02-24  2:52 Robin H. Johnson
2015-02-24  2:49 Robin H. Johnson
2015-02-23 23:55 Alex Legler
2015-02-23 23:55 Alex Legler
2015-02-23 20:59 Alex Legler
2015-02-23 20:59 Alex Legler
2015-02-23  0:05 Alex Legler
2015-02-23  0:05 Alex Legler
2015-02-23  0:05 Alex Legler
2015-02-23  0:05 Alex Legler
2015-02-23  0:05 Alex Legler
2015-02-22 23:01 Alex Legler
2015-02-21 21:36 Alex Legler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424749184.51aea5a8f68dc5d4a49e6795ff83d439c7f03942.robbat2@gentoo \
    --to=robbat2@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox