diff options
author | 2015-02-23 01:05:05 +0100 | |
---|---|---|
committer | 2015-02-23 01:05:05 +0100 | |
commit | 3aeff5af03460eea82b31c493c6bfa635f80cf72 (patch) | |
tree | 0c1f104f7d83a174d95c200f513172f77744b1cd | |
parent | Add id resolving helper (diff) | |
download | backend-3aeff5af03460eea82b31c493c6bfa635f80cf72.tar.gz backend-3aeff5af03460eea82b31c493c6bfa635f80cf72.tar.bz2 backend-3aeff5af03460eea82b31c493c6bfa635f80cf72.zip |
Implement --info
-rwxr-xr-x | ag | 23 | ||||
-rw-r--r-- | lib/storage.rb | 18 |
2 files changed, 40 insertions, 1 deletions
@@ -42,6 +42,12 @@ op = OptionParser.new do |opts| $options.action = :do_delete end + opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do + abort 'Can only select one action' if $options.action != nil + + $options.action = :do_info + end + opts.on('--reindex', 'Reindex message. Needs --file') do abort 'Can only select one action' if $options.action != nil @@ -144,7 +150,22 @@ def do_reindex end def do_info - abort 'Come back later.' + id = Ag::Utils.resolve_id + + begin + message = Ag::Storage.get($options.name, id) + + raise 'No such message' unless message + + require 'pp' + str = "Message #{id}" + $stderr.puts str + $stderr.puts '-' * str.length + + pp message['_source'] + rescue => e + $stderr.puts "Cannot display message: #{e}" + end end ############################################################################### diff --git a/lib/storage.rb b/lib/storage.rb index 37083fa..b4a518e 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -220,4 +220,22 @@ module Ag::Storage result['hits']['total'] end + def get(list, id) + result = $es.search( + index: 'ml-' + list, + size: 1, + body: { + query: { + filtered: { + filter: { + term: { _id: id } + } + } + } + } + ) + + return nil if result['hits']['total'] == 0 + result['hits']['hits'].first + end end
\ No newline at end of file |