tail_f_rabbitmq 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/fir_tail_f +14 -0
- data/bin/setup +7 -0
- data/lib/tail_f_rabbitmq/cli.rb +19 -0
- data/lib/tail_f_rabbitmq/patches/concern.rb +148 -0
- data/lib/tail_f_rabbitmq/patches/native_patch.rb +227 -0
- data/lib/tail_f_rabbitmq/patches/os_patch.rb +29 -0
- data/lib/tail_f_rabbitmq/patches.rb +3 -0
- data/lib/tail_f_rabbitmq/util/config.rb +36 -0
- data/lib/tail_f_rabbitmq/util.rb +50 -0
- data/lib/tail_f_rabbitmq/version.rb +3 -0
- data/lib/tail_f_rabbitmq.rb +13 -0
- data/tail_f_rabbitmq.gemspec +35 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 987baab2c19e3419f7ed92bf39a4eb2c9e9db095
|
4
|
+
data.tar.gz: 50051eee353e6937fef99e2d449a151078569157
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9ad1f598fc87e77bde6168f9763579785b7971efa3558057b50fffca9bbfedfc58179f87e24773907048ff22223889cac3086f143392f41918c9aaaa84c9be1
|
7
|
+
data.tar.gz: 63b519bc7aa8cb4b0ccc6d878e62a556a89db81f3a21b994085614834913c44229fb2f62dfef04cea49e377dbbafe742a54c9b40c8d0c356c392bbb558488142
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# TailFRabbitmq
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tail_f_rabbitmq`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'tail_f_rabbitmq'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install tail_f_rabbitmq
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tail_f_rabbitmq.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tail_f_rabbitmq"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/fir_tail_f
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module FIR
|
2
|
+
class CLI < Thor
|
3
|
+
desc 'monitor', 'monitor directoy'
|
4
|
+
def monitor(*args)
|
5
|
+
TailFRabbitmq.monitor(args.first)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "reset", "reset config"
|
9
|
+
def reset
|
10
|
+
TailFRabbitmq.reset_config
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'help', 'Describe available commands or one specific command (aliases: `h`).'
|
14
|
+
map Thor::HELP_MAPPINGS => :help
|
15
|
+
def help(command = nil, subcommand = false)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# A typical module looks like this:
|
5
|
+
#
|
6
|
+
# module M
|
7
|
+
# def self.included(base)
|
8
|
+
# base.extend ClassMethods
|
9
|
+
# base.class_eval do
|
10
|
+
# scope :disabled, -> { where(disabled: true) }
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# module ClassMethods
|
15
|
+
# ...
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# By using <tt>ActiveSupport::Concern</tt> the above module could instead be
|
20
|
+
# written as:
|
21
|
+
#
|
22
|
+
# require 'active_support/concern'
|
23
|
+
#
|
24
|
+
# module M
|
25
|
+
# extend ActiveSupport::Concern
|
26
|
+
#
|
27
|
+
# included do
|
28
|
+
# scope :disabled, -> { where(disabled: true) }
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# class_methods do
|
32
|
+
# ...
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Moreover, it gracefully handles module dependencies. Given a +Foo+ module
|
37
|
+
# and a +Bar+ module which depends on the former, we would typically write the
|
38
|
+
# following:
|
39
|
+
#
|
40
|
+
# module Foo
|
41
|
+
# def self.included(base)
|
42
|
+
# base.class_eval do
|
43
|
+
# def self.method_injected_by_foo
|
44
|
+
# ...
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# module Bar
|
51
|
+
# def self.included(base)
|
52
|
+
# base.method_injected_by_foo
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# class Host
|
57
|
+
# include Foo # We need to include this dependency for Bar
|
58
|
+
# include Bar # Bar is the module that Host really needs
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# But why should +Host+ care about +Bar+'s dependencies, namely +Foo+? We
|
62
|
+
# could try to hide these from +Host+ directly including +Foo+ in +Bar+:
|
63
|
+
#
|
64
|
+
# module Bar
|
65
|
+
# include Foo
|
66
|
+
# def self.included(base)
|
67
|
+
# base.method_injected_by_foo
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# class Host
|
72
|
+
# include Bar
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# Unfortunately this won't work, since when +Foo+ is included, its <tt>base</tt>
|
76
|
+
# is the +Bar+ module, not the +Host+ class. With <tt>ActiveSupport::Concern</tt>,
|
77
|
+
# module dependencies are properly resolved:
|
78
|
+
#
|
79
|
+
# require 'active_support/concern'
|
80
|
+
#
|
81
|
+
# module Foo
|
82
|
+
# extend ActiveSupport::Concern
|
83
|
+
# included do
|
84
|
+
# def self.method_injected_by_foo
|
85
|
+
# ...
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# module Bar
|
91
|
+
# extend ActiveSupport::Concern
|
92
|
+
# include Foo
|
93
|
+
#
|
94
|
+
# included do
|
95
|
+
# self.method_injected_by_foo
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# class Host
|
100
|
+
# include Bar # It works, now Bar takes care of its dependencies
|
101
|
+
# end
|
102
|
+
module Concern
|
103
|
+
class MultipleIncludedBlocks < StandardError #:nodoc:
|
104
|
+
def initialize
|
105
|
+
super "Cannot define multiple 'included' blocks for a Concern"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.extended(base) #:nodoc:
|
110
|
+
base.instance_variable_set(:@_dependencies, [])
|
111
|
+
end
|
112
|
+
|
113
|
+
def append_features(base)
|
114
|
+
if base.instance_variable_defined?(:@_dependencies)
|
115
|
+
base.instance_variable_get(:@_dependencies) << self
|
116
|
+
return false
|
117
|
+
else
|
118
|
+
return false if base < self
|
119
|
+
@_dependencies.each { |dep| base.send(:include, dep) }
|
120
|
+
super
|
121
|
+
base.extend const_get(:ClassMethods) if const_defined?(:ClassMethods)
|
122
|
+
base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def included(base = nil, &block)
|
127
|
+
if base.nil?
|
128
|
+
fail MultipleIncludedBlocks if instance_variable_defined?(:@_included_block)
|
129
|
+
|
130
|
+
@_included_block = block
|
131
|
+
else
|
132
|
+
super
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def class_methods(&class_methods_module_definition)
|
137
|
+
if const_defined?(:ClassMethods, false)
|
138
|
+
mod = const_get(:ClassMethods)
|
139
|
+
else
|
140
|
+
mod = const_set(:ClassMethods, Module.new)
|
141
|
+
end
|
142
|
+
|
143
|
+
mod.module_eval(&class_methods_module_definition)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
@@ -0,0 +1,227 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
5
|
+
# For example, '', ' ', +nil+, [], and {} are all blank.
|
6
|
+
#
|
7
|
+
# This simplifies
|
8
|
+
#
|
9
|
+
# address.nil? || address.empty?
|
10
|
+
#
|
11
|
+
# to
|
12
|
+
#
|
13
|
+
# address.blank?
|
14
|
+
#
|
15
|
+
# @return [true, false]
|
16
|
+
def blank?
|
17
|
+
respond_to?(:empty?) ? empty? : !self
|
18
|
+
end
|
19
|
+
|
20
|
+
# An object is present if it's not blank.
|
21
|
+
#
|
22
|
+
# @return [true, false]
|
23
|
+
def present?
|
24
|
+
!blank?
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the receiver if it's present otherwise returns +nil+.
|
28
|
+
# <tt>object.presence</tt> is equivalent to
|
29
|
+
#
|
30
|
+
# object.present? ? object : nil
|
31
|
+
#
|
32
|
+
# For example, something like
|
33
|
+
#
|
34
|
+
# state = params[:state] if params[:state].present?
|
35
|
+
# country = params[:country] if params[:country].present?
|
36
|
+
# region = state || country || 'US'
|
37
|
+
#
|
38
|
+
# becomes
|
39
|
+
#
|
40
|
+
# region = params[:state].presence || params[:country].presence || 'US'
|
41
|
+
#
|
42
|
+
# @return [Object]
|
43
|
+
def presence
|
44
|
+
self if present?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class NilClass
|
49
|
+
# +nil+ is blank:
|
50
|
+
#
|
51
|
+
# nil.blank? # => true
|
52
|
+
#
|
53
|
+
# @return [true]
|
54
|
+
def blank?
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class FalseClass
|
60
|
+
# +false+ is blank:
|
61
|
+
#
|
62
|
+
# false.blank? # => true
|
63
|
+
#
|
64
|
+
# @return [true]
|
65
|
+
def blank?
|
66
|
+
true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class TrueClass
|
71
|
+
# +true+ is not blank:
|
72
|
+
#
|
73
|
+
# true.blank? # => false
|
74
|
+
#
|
75
|
+
# @return [false]
|
76
|
+
def blank?
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Array
|
82
|
+
# An array is blank if it's empty:
|
83
|
+
#
|
84
|
+
# [].blank? # => true
|
85
|
+
# [1,2,3].blank? # => false
|
86
|
+
#
|
87
|
+
# @return [true, false]
|
88
|
+
alias_method :blank?, :empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
class Hash
|
92
|
+
# A hash is blank if it's empty:
|
93
|
+
#
|
94
|
+
# {}.blank? # => true
|
95
|
+
# { key: 'value' }.blank? # => false
|
96
|
+
#
|
97
|
+
# @return [true, false]
|
98
|
+
alias_method :blank?, :empty?
|
99
|
+
end
|
100
|
+
|
101
|
+
class String
|
102
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
103
|
+
|
104
|
+
# A string is blank if it's empty or contains whitespaces only:
|
105
|
+
#
|
106
|
+
# ''.blank? # => true
|
107
|
+
# ' '.blank? # => true
|
108
|
+
# "\t\n\r".blank? # => true
|
109
|
+
# ' blah '.blank? # => false
|
110
|
+
#
|
111
|
+
# Unicode whitespace is supported:
|
112
|
+
#
|
113
|
+
# "\u00a0".blank? # => true
|
114
|
+
#
|
115
|
+
# @return [true, false]
|
116
|
+
def blank?
|
117
|
+
BLANK_RE === self
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Numeric #:nodoc:
|
122
|
+
# No number is blank:
|
123
|
+
#
|
124
|
+
# 1.blank? # => false
|
125
|
+
# 0.blank? # => false
|
126
|
+
#
|
127
|
+
# @return [false]
|
128
|
+
def blank?
|
129
|
+
false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class Hash
|
134
|
+
# Returns a new hash with all keys converted using the block operation.
|
135
|
+
#
|
136
|
+
# hash = { name: 'Rob', age: '28' }
|
137
|
+
#
|
138
|
+
# hash.transform_keys{ |key| key.to_s.upcase }
|
139
|
+
# # => {"NAME"=>"Rob", "AGE"=>"28"}
|
140
|
+
def transform_keys
|
141
|
+
return enum_for(:transform_keys) unless block_given?
|
142
|
+
result = self.class.new
|
143
|
+
each_key do |key|
|
144
|
+
result[yield(key)] = self[key]
|
145
|
+
end
|
146
|
+
result
|
147
|
+
end
|
148
|
+
|
149
|
+
# Returns a new hash with all keys converted to symbols, as long as
|
150
|
+
# they respond to +to_sym+.
|
151
|
+
#
|
152
|
+
# hash = { 'name' => 'Rob', 'age' => '28' }
|
153
|
+
#
|
154
|
+
# hash.symbolize_keys
|
155
|
+
# # => {:name=>"Rob", :age=>"28"}
|
156
|
+
def symbolize_keys
|
157
|
+
transform_keys { |key| key.to_sym rescue key }
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns a new hash with all keys converted by the block operation.
|
161
|
+
# This includes the keys from the root hash and from all
|
162
|
+
# nested hashes and arrays.
|
163
|
+
#
|
164
|
+
# hash = { person: { name: 'Rob', age: '28' } }
|
165
|
+
#
|
166
|
+
# hash.deep_transform_keys{ |key| key.to_s.upcase }
|
167
|
+
# # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
|
168
|
+
def deep_transform_keys(&block)
|
169
|
+
_deep_transform_keys_in_object(self, &block)
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns a new hash with all keys converted to symbols, as long as
|
173
|
+
# they respond to +to_sym+. This includes the keys from the root hash
|
174
|
+
# and from all nested hashes and arrays.
|
175
|
+
#
|
176
|
+
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
|
177
|
+
#
|
178
|
+
# hash.deep_symbolize_keys
|
179
|
+
# # => {:person=>{:name=>"Rob", :age=>"28"}}
|
180
|
+
def deep_symbolize_keys
|
181
|
+
deep_transform_keys { |key| key.to_sym rescue key }
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
# support methods for deep transforming nested hashes and arrays
|
187
|
+
def _deep_transform_keys_in_object(object, &block)
|
188
|
+
case object
|
189
|
+
when Hash
|
190
|
+
object.each_with_object({}) do |(key, value), result|
|
191
|
+
result[yield(key)] = _deep_transform_keys_in_object(value, &block)
|
192
|
+
end
|
193
|
+
when Array
|
194
|
+
object.map { |e| _deep_transform_keys_in_object(e, &block) }
|
195
|
+
else
|
196
|
+
object
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class File
|
202
|
+
class << self
|
203
|
+
# A binary file is Mach-O dSYM
|
204
|
+
#
|
205
|
+
# @return [true, false]
|
206
|
+
def dsym?(file_path)
|
207
|
+
!(`file -b #{file_path}` =~ /dSYM/).nil?
|
208
|
+
end
|
209
|
+
|
210
|
+
# A file is ASCII text
|
211
|
+
#
|
212
|
+
# @return [true, false]
|
213
|
+
def text?(file_path)
|
214
|
+
!(`file -b #{file_path}` =~ /text/).nil?
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
class String
|
220
|
+
# Convert String encoding to UTF-8
|
221
|
+
#
|
222
|
+
# @return string
|
223
|
+
def to_utf8
|
224
|
+
encode(Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: '')
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OS
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def windows?
|
7
|
+
!(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def mac?
|
11
|
+
!(/darwin/ =~ RUBY_PLATFORM).nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def unix?
|
15
|
+
!OS.windows?
|
16
|
+
end
|
17
|
+
|
18
|
+
def linux?
|
19
|
+
OS.unix? && !OS.mac?
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_locale
|
23
|
+
system 'export LC_ALL=en_US.UTF-8'
|
24
|
+
system 'export LC_CTYPE=en_US.UTF-8'
|
25
|
+
system 'export LANG=en_US.UTF-8'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module FIR
|
4
|
+
module Config
|
5
|
+
CONFIG_PATH = "#{ENV['HOME']}/.tail_f_rabbitmq_config"
|
6
|
+
def default_config
|
7
|
+
config = {
|
8
|
+
url: "amqp://guest:guest@localhost:5672",
|
9
|
+
queue: "log_line",
|
10
|
+
eof: "END"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
unless File.exist?(CONFIG_PATH)
|
16
|
+
@config = default_config
|
17
|
+
write_config @config
|
18
|
+
end
|
19
|
+
@config ||= YAML.load_file(CONFIG_PATH).deep_symbolize_keys
|
20
|
+
end
|
21
|
+
|
22
|
+
def reload_config
|
23
|
+
@config = YAML.load_file(CONFIG_PATH).deep_symbolize_keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def write_config(hash)
|
27
|
+
File.open(CONFIG_PATH, 'w+') { |f| f << YAML.dump(hash) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset_config
|
31
|
+
@config = default_config
|
32
|
+
write_config @config
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rb-inotify'
|
3
|
+
require_relative './util/config'
|
4
|
+
module FIR
|
5
|
+
module Util
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
include FIR::Config
|
10
|
+
|
11
|
+
def monitor file_path
|
12
|
+
@conn = Bunny.new(config[:url])
|
13
|
+
@conn.start
|
14
|
+
@ch = @conn.create_channel
|
15
|
+
@q = @ch.queue(config[:queue], :auto_delete => true)
|
16
|
+
@x = @ch.default_exchange
|
17
|
+
notifier = INotify::Notifier.new
|
18
|
+
notifier.watch file_path, :create, :recursive do |event|
|
19
|
+
Thread.new do
|
20
|
+
tail_f event.absolute_name do |lines, queue|
|
21
|
+
send_msg event.name, lines
|
22
|
+
queue.stop if lines.include? config[:eof]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
notifier.run
|
27
|
+
end
|
28
|
+
|
29
|
+
def tail_f file_path
|
30
|
+
queue = INotify::Notifier.new
|
31
|
+
open(file_path) do |file|
|
32
|
+
yield file.read, queue # 先处理一次(create 时候的数据)
|
33
|
+
queue.watch(file_path, :modify) do
|
34
|
+
yield file.read, queue
|
35
|
+
end
|
36
|
+
queue.run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def send_msg(name, line)
|
41
|
+
msg = {
|
42
|
+
name: name,
|
43
|
+
line: line
|
44
|
+
}
|
45
|
+
@x.publish(msg.to_json, :routing_key => @q.name) if line != ""
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "./tail_f_rabbitmq/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'thor'
|
4
|
+
require 'bunny'
|
5
|
+
require_relative "./tail_f_rabbitmq/patches"
|
6
|
+
require_relative "./tail_f_rabbitmq/util"
|
7
|
+
require_relative "./tail_f_rabbitmq/cli"
|
8
|
+
|
9
|
+
module TailFRabbitmq
|
10
|
+
include FIR::Util
|
11
|
+
end
|
12
|
+
|
13
|
+
FIR::CLI.start ARGV
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tail_f_rabbitmq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tail_f_rabbitmq"
|
8
|
+
spec.version = TailFRabbitmq::VERSION
|
9
|
+
spec.authors = ["atpking"]
|
10
|
+
spec.email = ["atpking@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{tail_f directory and send to rabbitmq}
|
13
|
+
spec.description = %q{like tail -f command, this gem should caputre the change of files and send it to rabbitmq}
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "bin"
|
25
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.executables = ["fir_tail_f"]
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency "thor"
|
32
|
+
spec.add_development_dependency "json"
|
33
|
+
spec.add_development_dependency "rb-inotify"
|
34
|
+
spec.add_development_dependency "bunny"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tail_f_rabbitmq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- atpking
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rb-inotify
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bunny
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: like tail -f command, this gem should caputre the change of files and
|
98
|
+
send it to rabbitmq
|
99
|
+
email:
|
100
|
+
- atpking@gmail.com
|
101
|
+
executables:
|
102
|
+
- fir_tail_f
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/fir_tail_f
|
112
|
+
- bin/setup
|
113
|
+
- lib/tail_f_rabbitmq.rb
|
114
|
+
- lib/tail_f_rabbitmq/cli.rb
|
115
|
+
- lib/tail_f_rabbitmq/patches.rb
|
116
|
+
- lib/tail_f_rabbitmq/patches/concern.rb
|
117
|
+
- lib/tail_f_rabbitmq/patches/native_patch.rb
|
118
|
+
- lib/tail_f_rabbitmq/patches/os_patch.rb
|
119
|
+
- lib/tail_f_rabbitmq/util.rb
|
120
|
+
- lib/tail_f_rabbitmq/util/config.rb
|
121
|
+
- lib/tail_f_rabbitmq/version.rb
|
122
|
+
- tail_f_rabbitmq.gemspec
|
123
|
+
homepage:
|
124
|
+
licenses: []
|
125
|
+
metadata:
|
126
|
+
allowed_push_host: https://rubygems.org
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.6
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: tail_f directory and send to rabbitmq
|
147
|
+
test_files: []
|
148
|
+
has_rdoc:
|