13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/em-beanstalk/shell.rb', line 13
def receive_line(line)
line.chomp!
line.gsub!(/^\s+/, '')
df = case(line)
when /^\s*$/ then
nil
when /^use / then
tube = line.gsub(/use /, '')
df = @jack.use(tube)
df.callback { |tube| puts "Using #{tube}" } unless df.nil?
df
when /^watch / then
tube = line.gsub(/watch /, '')
df = @jack.watch(tube)
df.callback { |tube| puts "Watching #{tube}" } unless df.nil?
df
when /^put / then
msg = line.gsub(/put /, '')
df = @jack.put(msg)
df.callback { |id| puts "Inserted job #{id}" }
df
when /^delete / then
id = line.gsub(/delete /, '').to_i
job = EM::Beanstalk::Job.new(@jack, id, "asdf")
df = job.delete
df.callback { puts "Deleted" }
df
when 'reserve' then
df = @jack.reserve
df.callback { |job| puts "Reserved #{job}" }
df
when 'list-tubes' then
df = @jack.list
df.callback { |tubes| pp tubes }
df
when 'list-watched' then
df = @jack.list(:watched)
df.callback { |tubes| pp tubes }
df
when 'list-used' then
df = @jack.list(:used)
df.callback { |tube| puts "Using #{tube}" }
df
when 'stats' then
df = @jack.stats
df.callback { |stats| pp stats }
df
when /^stats-tube\s+(.*)$/ then
df = @jack.stats(:tube, $1)
df.callback { |stats| pp stats }
df
when /^stats-job\s+(\d+)/ then
j = EM::Beanstalk::Job.new(@jack, $1, "blah")
df = j.stats
df.callback { |stats| pp stats }
df
when 'help' then
msg = "COMMANDS:\n"
msg << " put <msg> - put message onto beanstalk\n"
msg << " reserve - reserve a job on beanstalk\n"
msg << " delete <id> - delete message with ID <id>\n"
msg << "\n"
msg << " use <tube> - use tube for messages\n"
msg << " watch <tube> - add <tube to watch list for messages\n"
msg << "\n"
msg << " stats - display beanstalk stats\n"
msg << " stats-tube <tube> - display tube stats\n"
msg << " stats-job <id> - display job stats\n"
msg << "\n"
msg << " list-tubes - display beanstalk tubes\n"
msg << " list-used - display the currently used tube\n"
msg << " list-watched - display the currently watched tubes\n"
msg << "\n"
msg << " help - this help text\n"
msg << " quit - quit application\n"
puts msg
nil
when 'quit' then
EM.stop_event_loop
nil
end
unless df.nil?
df.callback { print "> " }
df.errback { print "> " }
end
print "> "
end
|