miu-sana 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/miu-sana.rb +1 -0
- data/lib/miu/nodes/sana.rb +6 -0
- data/lib/miu/nodes/sana/core_ext.rb +5 -0
- data/lib/miu/nodes/sana/node.rb +111 -0
- data/lib/miu/nodes/sana/server.rb +22 -0
- data/lib/miu/nodes/sana/subscriber.rb +50 -0
- data/lib/miu/nodes/sana/version.rb +7 -0
- data/miu-sana.gemspec +27 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9e87d1650880949302cf903aee57102a938afa6
|
4
|
+
data.tar.gz: 2ba9d47396dfe92ec117f8dbe93cc231abbc268c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b8cebaf9fd9ef04dfb1fd10c2bc5ef39d5ab4d1e3b64c95fc042c5323af220cbe14ebd92dfa346858b6bf612b8c9f3227cb9500d4a5c95e7e2879b638b47db8
|
7
|
+
data.tar.gz: 5057a46fad0394fd8898bc0d5d3e656fff19c0d938c643e71ac04ed7b74da36c6deb5a583169175314ca561f1cbc27c6e4e93fa09699d467106022c70d8632ee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 mashiro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Miu::Sana
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'miu-sana'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install miu-sana
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/miu-sana.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'miu/nodes/sana'
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'miu'
|
2
|
+
require 'groonga'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'miu/nodes/sana/server'
|
6
|
+
require 'miu/nodes/sana/subscriber'
|
7
|
+
|
8
|
+
module Miu
|
9
|
+
module Nodes
|
10
|
+
module Sana
|
11
|
+
class Node
|
12
|
+
include Miu::Node
|
13
|
+
description 'Logging node for miu'
|
14
|
+
|
15
|
+
DEFAULT_PORT = Miu.default_port + 37
|
16
|
+
|
17
|
+
attr_reader :server, :subscriber
|
18
|
+
attr_reader :options
|
19
|
+
|
20
|
+
def initialize(options)
|
21
|
+
@options = options
|
22
|
+
|
23
|
+
Miu::Logger.info "Options:"
|
24
|
+
@options.each do |k, v|
|
25
|
+
Miu::Logger.info " #{k}: #{v}"
|
26
|
+
end
|
27
|
+
|
28
|
+
establish options[:database]
|
29
|
+
|
30
|
+
@server = Server.new options[:bind], options[:port]
|
31
|
+
@subscriber = Subscriber.new options['sub-host'], options['sub-port'], options['sub-tag']
|
32
|
+
@subscriber.async.run
|
33
|
+
|
34
|
+
[:INT, :TERM].each do |sig|
|
35
|
+
trap(sig) { exit }
|
36
|
+
end
|
37
|
+
|
38
|
+
sleep
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def establish(path)
|
44
|
+
FileUtils.mkdir_p File.dirname(path)
|
45
|
+
|
46
|
+
::Groonga::Context.default_options = {:encoding => :utf8}
|
47
|
+
if File.exist? path
|
48
|
+
::Groonga::Database.open path
|
49
|
+
else
|
50
|
+
::Groonga::Database.create :path => path
|
51
|
+
end
|
52
|
+
|
53
|
+
::Groonga::Schema.define do |schema|
|
54
|
+
schema.create_table 'networks', :type => :patricia_trie, :key_type => :short_text
|
55
|
+
schema.create_table 'rooms', :type => :patricia_trie, :key_type => :short_text
|
56
|
+
schema.create_table 'users', :type => :patricia_trie, :key_type => :short_text
|
57
|
+
schema.create_table 'messages', :type => :array
|
58
|
+
schema.create_table 'terms', :type => :patricia_trie, :key_normalize => true, :default_tokenizer => :bigram
|
59
|
+
|
60
|
+
schema.change_table 'networks' do |table|
|
61
|
+
table.short_text 'name'
|
62
|
+
end
|
63
|
+
schema.change_table 'rooms' do |table|
|
64
|
+
table.reference 'network', 'networks'
|
65
|
+
table.short_text 'name'
|
66
|
+
end
|
67
|
+
schema.change_table 'users' do |table|
|
68
|
+
table.reference 'network', 'networks'
|
69
|
+
table.short_text 'name'
|
70
|
+
end
|
71
|
+
schema.change_table 'messages' do |table|
|
72
|
+
table.reference 'network', 'networks'
|
73
|
+
table.reference 'room', 'rooms'
|
74
|
+
table.reference 'user', 'users'
|
75
|
+
table.short_text 'text'
|
76
|
+
table.short_text 'meta'
|
77
|
+
table.time 'time'
|
78
|
+
end
|
79
|
+
schema.change_table 'terms' do |table|
|
80
|
+
table.index 'networks.name'
|
81
|
+
table.index 'rooms.name'
|
82
|
+
table.index 'users.name'
|
83
|
+
table.index 'messages.text'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
register :sana do
|
89
|
+
desc 'start', %(Start miu-sana node)
|
90
|
+
option :bind, :type => :string, :default => '127.0.0.1', :desc => 'bind address', :aliases => '-a'
|
91
|
+
option :port, :type => :numeric, :default => DEFAULT_PORT, :desc => 'listen port', :aliases => '-p'
|
92
|
+
option :database, :type => :string, :default => 'db/groonga/sana.db', :desc => 'database path'
|
93
|
+
add_miu_sub_options 'miu.input.'
|
94
|
+
def start
|
95
|
+
Node.new options
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'init', %(Generates a miu-sana configurations)
|
99
|
+
def init
|
100
|
+
config <<-EOS
|
101
|
+
Miu.watch 'sana' do |w|
|
102
|
+
w.start = 'miu sana start'
|
103
|
+
w.keepalive
|
104
|
+
end
|
105
|
+
EOS
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'miu/rpc'
|
2
|
+
require 'groonga'
|
3
|
+
|
4
|
+
module Miu
|
5
|
+
module Nodes
|
6
|
+
module Sana
|
7
|
+
class Server
|
8
|
+
class Handler
|
9
|
+
def select(table, query)
|
10
|
+
Groonga[table].select(query).map(&:attributes)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :server
|
15
|
+
|
16
|
+
def initialize(bind, port)
|
17
|
+
@server = Miu::RPC::Server.new "tcp://#{bind}:#{port}", Handler.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'miu'
|
2
|
+
require 'groonga'
|
3
|
+
|
4
|
+
module Miu
|
5
|
+
module Nodes
|
6
|
+
module Sana
|
7
|
+
class Subscriber
|
8
|
+
include Miu::Subscriber
|
9
|
+
include Celluloid::ZMQ
|
10
|
+
socket_type Celluloid::ZMQ::SubSocket
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@networks = Groonga['networks']
|
15
|
+
@rooms = Groonga['rooms']
|
16
|
+
@users = Groonga['users']
|
17
|
+
@messages = Groonga['messages']
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_text(tag, msg)
|
21
|
+
add_message(msg)
|
22
|
+
Miu::Logger.debug "[ADD] #{msg.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def add_message(msg)
|
28
|
+
network_name = msg.network.name
|
29
|
+
room_name = msg.content.room.name
|
30
|
+
user_name = msg.content.user.name
|
31
|
+
text = msg.content.text
|
32
|
+
meta = MultiJson.encode msg.content.meta
|
33
|
+
time = msg.time
|
34
|
+
|
35
|
+
network = @networks[network_name] || @networks.add(network_name, :name => network_name)
|
36
|
+
room = @rooms[room_name] || @rooms.add(room_name, :network => network, :name => room_name)
|
37
|
+
user = @users[user_name] || @users.add(user_name, :network => network, :name => user_name)
|
38
|
+
@messages.add({
|
39
|
+
:network => network,
|
40
|
+
:room => room,
|
41
|
+
:user => user,
|
42
|
+
:text => text,
|
43
|
+
:meta => meta,
|
44
|
+
:time => time
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/miu-sana.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'miu/nodes/sana/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'miu-sana'
|
8
|
+
spec.version = Miu::Nodes::Sana::VERSION
|
9
|
+
spec.authors = ['mashiro']
|
10
|
+
spec.email = ['mail@mashiro.org']
|
11
|
+
spec.description = %q{Logging node for miu}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/yuijo/miu-sana'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'miu', '>= 0.2.2'
|
22
|
+
spec.add_dependency 'miu-rpc', '>= 0.0.2'
|
23
|
+
spec.add_dependency 'rroonga', '>= 3.0.1'
|
24
|
+
spec.add_dependency 'multi_json', '>= 1.7.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: miu-sana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mashiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: miu
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: miu-rpc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rroonga
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
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: rspec
|
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: Logging node for miu
|
98
|
+
email:
|
99
|
+
- mail@mashiro.org
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/miu-sana.rb
|
110
|
+
- lib/miu/nodes/sana.rb
|
111
|
+
- lib/miu/nodes/sana/core_ext.rb
|
112
|
+
- lib/miu/nodes/sana/node.rb
|
113
|
+
- lib/miu/nodes/sana/server.rb
|
114
|
+
- lib/miu/nodes/sana/subscriber.rb
|
115
|
+
- lib/miu/nodes/sana/version.rb
|
116
|
+
- miu-sana.gemspec
|
117
|
+
homepage: https://github.com/yuijo/miu-sana
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.0.0
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Logging node for miu
|
141
|
+
test_files: []
|