-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfirehose
More file actions
executable file
·99 lines (87 loc) · 2.3 KB
/
Copy pathfirehose
File metadata and controls
executable file
·99 lines (87 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path('..', __dir__))
require 'bundler/setup'
require 'app/firehose_stream'
$stdout.sync = true
if ENV['ARLOG'] == '1'
ActiveRecord::Base.logger = Logger.new(STDOUT)
else
ActiveRecord::Base.logger = nil
end
def print_help
puts "Usage: #{$0} [options...]"
puts "Options:"
puts
puts " * Showing progress: [default: show in development]"
puts " -p = show progress dots for each received message"
puts " -np = don't show progress dots"
puts
puts " * Logging status changes: [default: log in any mode]"
puts " -ns = don't log status changes"
puts
puts " * Logging post text: [default: -lm in development, -nl in production]"
puts " -lm = log text of matching posts"
puts " -la = log text of every post"
puts " -nl = don't log posts"
puts
puts " * Saving posts to db: [default: -da in development, -dm in production]"
puts " -da = save all posts to database"
puts " -dm = save only matching posts to database"
puts " -nd = don't save any posts"
puts
puts " * Replaying missed events: [default: -nr in development, -r in production]"
puts " -r = pass a cursor param when connecting to replay any missed events"
puts " -nr = don't replay missed events"
puts " -r12345 = start from this specific cursor"
end
firehose = FirehoseStream.new(ENV['FIREHOSE'])
ARGV.each do |arg|
case arg
when '-p'
firehose.show_progress = true
when '-np'
firehose.show_progress = false
when '-ns'
firehose.log_status = false
when '-lm'
firehose.log_posts = :matching
when '-la'
firehose.log_posts = :all
when '-nl'
firehose.log_posts = false
when '-dm'
firehose.save_posts = :matching
when '-da'
firehose.save_posts = :all
when '-nd'
firehose.save_posts = false
when '-r'
firehose.replay_events = true
when /^\-r(\d+)$/
firehose.replay_events = true
firehose.start_cursor = $1.to_i
when '-nr'
firehose.replay_events = false
when '-h', '--help'
print_help
exit 0
else
puts "Unrecognized option: #{arg}"
print_help
exit 1
end
end
trap("SIGINT") {
puts
firehose.log "Stopping..."
EM.add_timer(0) {
firehose.stop
}
}
trap("SIGTERM") {
firehose.log "Shutting down the service..."
EM.add_timer(0) {
firehose.stop
}
}
firehose.start