aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-02-23 01:05:05 +0100
committerAlex Legler <alex@a3li.li>2015-02-23 01:05:05 +0100
commit3aeff5af03460eea82b31c493c6bfa635f80cf72 (patch)
tree0c1f104f7d83a174d95c200f513172f77744b1cd
parentAdd id resolving helper (diff)
downloadbackend-3aeff5af03460eea82b31c493c6bfa635f80cf72.tar.gz
backend-3aeff5af03460eea82b31c493c6bfa635f80cf72.tar.bz2
backend-3aeff5af03460eea82b31c493c6bfa635f80cf72.zip
Implement --info
-rwxr-xr-xag23
-rw-r--r--lib/storage.rb18
2 files changed, 40 insertions, 1 deletions
diff --git a/ag b/ag
index be04609..29ee0f2 100755
--- a/ag
+++ b/ag
@@ -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