peons 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/peons +128 -0
- data/lib/peons.rb +1 -1
- metadata +3 -2
data/bin/peons
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require "thor"
|
5
|
+
require File.expand_path("../lib/peons", File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class Peons::CLI < Thor
|
8
|
+
namespace :peons
|
9
|
+
|
10
|
+
PREFIX = "peons"
|
11
|
+
|
12
|
+
desc "summary", "Show a quick summary of all your peons."
|
13
|
+
def summary
|
14
|
+
h1 "Peons Reporting: Work work"
|
15
|
+
h2 "Total: %d" % queues.size
|
16
|
+
|
17
|
+
queues.each do |key|
|
18
|
+
h2 "%s (%d)" % [key, key.llen]
|
19
|
+
|
20
|
+
say "- backup: %d" % total_backups(key)
|
21
|
+
say "- errors: %d" % key[:errors].llen
|
22
|
+
end
|
23
|
+
|
24
|
+
say "\n" * 2
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "show QUEUE_NAME", "Show the details of a given queue."
|
28
|
+
def show(queue)
|
29
|
+
key = ns(PREFIX)[queue]
|
30
|
+
|
31
|
+
h1 "%s (%d)" % [key, key.llen]
|
32
|
+
|
33
|
+
backups(key) do |backup|
|
34
|
+
h2 backup
|
35
|
+
|
36
|
+
ns(backup).lrange(0, -1).each_with_index do |val, idx|
|
37
|
+
say "%2d. %s" % [idx+1, val]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
h2 "%s (displaying first 10)" % key[:errors]
|
42
|
+
|
43
|
+
key[:errors].lrange(0, 10).each_with_index do |error, idx|
|
44
|
+
say "%2d. %s" % [idx+1, error]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "harvest QUEUE_NAME", "Harvest all backups and merge them back."
|
49
|
+
def harvest(queue)
|
50
|
+
key = ns(PREFIX)[queue]
|
51
|
+
|
52
|
+
h1 "Harvesting: %s" % key
|
53
|
+
|
54
|
+
backups(key) do |backup|
|
55
|
+
h2 "Processing: %s" % backup
|
56
|
+
|
57
|
+
bak = ns(backup)
|
58
|
+
|
59
|
+
loop do
|
60
|
+
bak.rpoplpush(key)
|
61
|
+
|
62
|
+
break if bak.llen.zero?
|
63
|
+
end
|
64
|
+
|
65
|
+
say "- Cleaning up..."
|
66
|
+
bak.del
|
67
|
+
say "- Done!"
|
68
|
+
say
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "pristine QUEUE_NAME", "Clear all errors for a given queue."
|
73
|
+
def pristine(queue)
|
74
|
+
key = ns(PREFIX)[queue]
|
75
|
+
|
76
|
+
h1 "Clearing Errors: %s" % key
|
77
|
+
|
78
|
+
response = ask("Are you sure? (y/N)")
|
79
|
+
|
80
|
+
if response.downcase.strip == "y"
|
81
|
+
say
|
82
|
+
say "- Clearing %d errors." % key[:errors].llen
|
83
|
+
key[:errors].del
|
84
|
+
say "- Done!"
|
85
|
+
say
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def h1(str)
|
91
|
+
puts
|
92
|
+
puts str
|
93
|
+
puts "=" * str.size
|
94
|
+
end
|
95
|
+
|
96
|
+
def h2(str)
|
97
|
+
puts
|
98
|
+
puts str
|
99
|
+
puts "-" * str.size
|
100
|
+
end
|
101
|
+
|
102
|
+
def redis
|
103
|
+
Peons.redis
|
104
|
+
end
|
105
|
+
|
106
|
+
def ns(key)
|
107
|
+
Nest.new(key, redis)
|
108
|
+
end
|
109
|
+
|
110
|
+
def queues
|
111
|
+
redis.keys(ns(PREFIX)["*"]).
|
112
|
+
reject { |key| key.end_with?(":backup") or key.end_with?(":errors") }.
|
113
|
+
map { |key| Nest.new(key, redis) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def backups(key)
|
117
|
+
redis.keys(key["*"][:backup]).each { |e| yield e }
|
118
|
+
end
|
119
|
+
|
120
|
+
def total_backups(key)
|
121
|
+
redis.keys(key["*"][:backup]).inject(0) do |acc, key|
|
122
|
+
acc + redis.llen(key)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
Peons::CLI.start
|
128
|
+
|
data/lib/peons.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -65,6 +65,7 @@ extensions: []
|
|
65
65
|
extra_rdoc_files: []
|
66
66
|
|
67
67
|
files:
|
68
|
+
- bin/peons
|
68
69
|
- lib/peons.rb
|
69
70
|
- README.markdown
|
70
71
|
- LICENSE
|