ruboty-moneta 0.1.2 → 0.2.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 +4 -4
- data/README.md +24 -10
- data/lib/ruboty/moneta/brains/moneta.rb +47 -16
- data/lib/ruboty/moneta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deede0a29a8c8b4a33310ef97a27a915707f6f29
|
4
|
+
data.tar.gz: cee6611da47b099948ad515ad28dcdebfc183922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506f23e3c07404b42ba864c973f361ae6d47d05733d3a36416717cdc86c484a8104b767a007ecd59c7958e22e5ede2de543b83593438ce9557758f07a26d97c6
|
7
|
+
data.tar.gz: 04710fbb9577cd664d8577587ef97a52eee0a0b132224df0ba0000401279e71a3e5f44f0634434b1cab69e7a3876239b4c8f9666471afe45234caed0f65da6f9
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ gem 'ruboty-moneta'
|
|
18
18
|
please setting [backend_type](https://github.com/minad/moneta#supported-backends) to MONETA_BACKEND
|
19
19
|
|
20
20
|
|
21
|
-
```
|
21
|
+
```shell
|
22
22
|
MONETA_BACKEND="{backend_type}"
|
23
23
|
```
|
24
24
|
|
@@ -35,31 +35,45 @@ Sqlite3のfileパラメータを指定したいときは下記のようになり
|
|
35
35
|
# MONETA_#{Backend}_#{Options Hash}
|
36
36
|
MONETA_SQLITE_FILE = "{file path}"
|
37
37
|
```
|
38
|
+
### Setting replicate
|
39
|
+
|
40
|
+
複数のbackendに同時に書き込みます。
|
41
|
+
MONETA_BACKENDで設定されたbackendのデータをmasterとして扱います。
|
42
|
+
ストアの移行作業時などに使ってください
|
43
|
+
|
44
|
+
```
|
45
|
+
MONETA_BACKEND_SLAVE={"backend" or ["backend1", "backend2"]}
|
46
|
+
|
47
|
+
# example
|
48
|
+
|
49
|
+
# Replicate in YAML
|
50
|
+
MONETA_BACKEND_SLAVE="YAML"
|
51
|
+
|
52
|
+
# Replicate in YAML and File
|
53
|
+
MONETA_BACKEND_SLAVE=["YAML", "File"]
|
54
|
+
|
55
|
+
```
|
38
56
|
|
39
57
|
### example
|
40
58
|
|
41
|
-
####
|
59
|
+
#### use memory
|
42
60
|
|
43
61
|
```ruby
|
44
62
|
gem 'ruboty-moneta'
|
45
63
|
```
|
46
64
|
|
47
|
-
####
|
48
|
-
|
49
|
-
##### Gemfile
|
65
|
+
#### use File
|
50
66
|
|
51
67
|
```ruby
|
52
68
|
gem 'ruboty-moneta'
|
53
69
|
```
|
54
70
|
|
55
|
-
|
56
|
-
|
57
|
-
```shell:.dotenv
|
71
|
+
```shell
|
58
72
|
MONETA_BACKEND="File"
|
59
73
|
MONETA_FILE_DIR="./db"
|
60
74
|
```
|
61
75
|
|
62
|
-
####
|
76
|
+
#### use Sqlite
|
63
77
|
|
64
78
|
```ruby
|
65
79
|
gem 'ruboty-moneta'
|
@@ -79,7 +93,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
79
93
|
|
80
94
|
## Contributing
|
81
95
|
|
82
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rike422/ruboty-moneta. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
83
97
|
|
84
98
|
|
85
99
|
## License
|
@@ -6,7 +6,8 @@ module Ruboty
|
|
6
6
|
KEY = "brain"
|
7
7
|
|
8
8
|
attr_reader :thread
|
9
|
-
env :MONETA_BACKEND, "use moneta
|
9
|
+
env :MONETA_BACKEND, "use moneta backend (default: memory)"
|
10
|
+
env :MONETA_BACKEND_SLAVE, "use cloning data to slaves (defalut: nil)", optional: true
|
10
11
|
env :MONETA_SAVE_INTERVAL, "Interval sec to push data to moneta (default: 5)", optional: true
|
11
12
|
env :MONETA_NAMESPACE, "Moneta name space (default: ruboty)", optional: true
|
12
13
|
|
@@ -23,42 +24,59 @@ module Ruboty
|
|
23
24
|
# Override.
|
24
25
|
def validate!
|
25
26
|
super
|
26
|
-
Ruboty.die("#{self.class.usage}") unless
|
27
|
+
Ruboty.die("#{self.class.usage}") unless master_backend
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
32
|
def push
|
32
|
-
|
33
|
+
master[key] = data
|
33
34
|
end
|
34
35
|
|
35
36
|
def pull
|
36
|
-
if str =
|
37
|
-
|
37
|
+
if str = master[key]
|
38
|
+
str
|
38
39
|
end
|
39
40
|
rescue TypeError
|
40
41
|
end
|
41
42
|
|
43
|
+
def replicate
|
44
|
+
slaves.each do |slave|
|
45
|
+
slave[key] = data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def wait
|
50
|
+
sleep(interval)
|
51
|
+
end
|
52
|
+
|
42
53
|
def sync
|
43
54
|
loop do
|
44
55
|
wait
|
45
56
|
push
|
57
|
+
replicate
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
49
|
-
def
|
50
|
-
|
61
|
+
def interval
|
62
|
+
(ENV["MONETA_SAVE_INTERVAL"] || 5).to_i
|
51
63
|
end
|
52
64
|
|
53
|
-
def
|
54
|
-
|
65
|
+
def master_backend
|
66
|
+
(ENV["MONETA_BACKEND"] || "Memory").to_sym
|
55
67
|
end
|
56
68
|
|
57
|
-
def
|
58
|
-
|
69
|
+
def slave_backend
|
70
|
+
eval(ENV["MONETA_BACKEND_SLAVE"] || "")
|
71
|
+
rescue NameError
|
72
|
+
ENV["MONETA_BACKEND_SLAVE"]
|
59
73
|
end
|
60
74
|
|
61
|
-
def
|
75
|
+
def namespace
|
76
|
+
ENV["MONETA_NAMESPACE"] || "ruboty"
|
77
|
+
end
|
78
|
+
|
79
|
+
def fetch_option(backend)
|
62
80
|
prefix = backend.to_s.underscore.upcase
|
63
81
|
ENV.reduce({}) do |option, env|
|
64
82
|
match = env[0].to_s.match(/MONETA_#{prefix}_([A-Z_]+)$/)
|
@@ -68,12 +86,25 @@ module Ruboty
|
|
68
86
|
end
|
69
87
|
end
|
70
88
|
|
71
|
-
def
|
72
|
-
|
89
|
+
def master
|
90
|
+
@master ||= ::Moneta.new(master_backend, fetch_option(master_backend))
|
73
91
|
end
|
74
92
|
|
75
|
-
def
|
76
|
-
|
93
|
+
def slaves
|
94
|
+
@slaves ||=
|
95
|
+
if slave_backend.is_a?(String)
|
96
|
+
[::Moneta.new(slave_backend.to_sym, fetch_option(slave_backend))]
|
97
|
+
elsif slave_backend.is_a?(Array)
|
98
|
+
slave_backend.map do |slave_name|
|
99
|
+
::Moneta.new(slave_name.to_sym, fetch_option(slave_name))
|
100
|
+
end
|
101
|
+
else
|
102
|
+
[]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def key
|
107
|
+
@key ||= "#{namespace}:#{KEY}"
|
77
108
|
end
|
78
109
|
end
|
79
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-moneta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akira.takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|