elected 0.1.0 → 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/.travis.yml +25 -2
- data/README.md +15 -4
- data/lib/elected/lider.rb +2 -0
- data/lib/elected/logging.rb +92 -0
- data/lib/elected/senado.rb +2 -0
- data/lib/elected/version.rb +1 -1
- data/lib/elected.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b5c89ac46abb1a6ea65b8920deceef50191c861
|
4
|
+
data.tar.gz: 671056c5313758131924eb017b72c7c94755072f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec2c9051972ec2bbbfccc9d5fb8dca3e310dd610edaa3bdda0cc9668b039b0f73a8c522a5f92c8e01f4eabec1031c77a511dd10b90b6977af28ffc17ee06ccb
|
7
|
+
data.tar.gz: 844371981fbede73461956dcd1c87e46c6b09a06fb45037e2d3a19dfab9feb14f0536b5736eeb072e245d1b373875d7966cc49e578f7108aa405638b0fce4979
|
data/.travis.yml
CHANGED
@@ -1,4 +1,27 @@
|
|
1
|
+
before_install: gem install bundler -v 1.10.6
|
2
|
+
|
1
3
|
language: ruby
|
4
|
+
jdk:
|
5
|
+
- oraclejdk8
|
2
6
|
rvm:
|
3
|
-
- 2.0.0
|
4
|
-
|
7
|
+
- ruby-2.0.0-p598
|
8
|
+
- ruby-2.2.0
|
9
|
+
- jruby-9.0.0.0
|
10
|
+
- jruby-head
|
11
|
+
services:
|
12
|
+
- redis-server
|
13
|
+
env:
|
14
|
+
global:
|
15
|
+
- REDIS_URL="redis://localhost:6379/0"
|
16
|
+
- JRUBY_OPTS="--server -J-Dfile.encoding=utf8 --2.0"
|
17
|
+
install:
|
18
|
+
- bundle install --jobs=3 --retry=3
|
19
|
+
script:
|
20
|
+
- bundle exec rspec
|
21
|
+
notifications:
|
22
|
+
email:
|
23
|
+
recipients:
|
24
|
+
- aemadrid@gmail.com
|
25
|
+
on_success: change
|
26
|
+
on_failure: change
|
27
|
+
sudo: false
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[](https://travis-ci.org/simple-finance/elected)
|
2
|
+
[](https://codeclimate.com/github/simple-finance/elected)
|
3
|
+
[](https://hakiri.io/github/simple-finance/elected/master)
|
4
|
+
[](https://gitter.im/simple-finance/elected?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
5
|
+
|
1
6
|
# Elected - A ruby distributed leader election through Redis locks.
|
2
7
|
|
3
8
|
> Elect a leader out of many processes and run code only in one of your servers at a time.
|
@@ -61,17 +66,23 @@ Make sure you have at least 1 redis instances up.
|
|
61
66
|
|
62
67
|
## Disclaimer
|
63
68
|
|
64
|
-
|
69
|
+
The hard work of securing a distributed lock is all done through the great [redlock](https://github.com/leandromoreira/redlock-rb) gem. Thanks to [Leandro Moreira](https://github.com/leandromoreira) for his hard work.
|
70
|
+
This code, thanks to Redlock, implements an algorithm which is currently a proposal, it was not formally analyzed.
|
71
|
+
Make sure to understand how it works before using it in your production environments.
|
72
|
+
You can see discussion about this approach at [reddit](http://www.reddit.com/r/programming/comments/2nt0nq/distributed_lock_using_redis_implemented_in_ruby/).
|
65
73
|
|
66
74
|
## Development
|
67
75
|
|
68
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
77
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
69
78
|
|
70
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
80
|
+
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).
|
71
81
|
|
72
82
|
## Contributing
|
73
83
|
|
74
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/simple-finance/elected.
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/simple-finance/elected.
|
85
|
+
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.
|
75
86
|
|
76
87
|
|
77
88
|
## License
|
data/lib/elected/lider.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Elected
|
4
|
+
module Logging
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def debug_var(var_name, var, meth = :inspect, level = :debug)
|
13
|
+
msg = var.nil? ? 'NIL' : var.send(meth)
|
14
|
+
msg = msg[0..-2] if msg[-1, 1] == "\n"
|
15
|
+
klass = var.is_a?(Class) ? var.name : var.class.name
|
16
|
+
Elected.logger.send level, "#{log_prefix} #{var_name} : (#{klass}:#{var.object_id}) #{msg}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def log(string, type = :debug)
|
20
|
+
msg = "#{log_prefix} #{string}"
|
21
|
+
Elected.logger.send type, msg
|
22
|
+
end
|
23
|
+
|
24
|
+
def debug(string)
|
25
|
+
log string, :debug
|
26
|
+
end
|
27
|
+
|
28
|
+
def info(string)
|
29
|
+
log string, :info
|
30
|
+
end
|
31
|
+
|
32
|
+
def warn(string)
|
33
|
+
log string, :warn
|
34
|
+
end
|
35
|
+
|
36
|
+
def error(string)
|
37
|
+
log string, :error
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_prefix(length = 60)
|
41
|
+
prefixes = [name]
|
42
|
+
label = log_prefix_labels.last
|
43
|
+
prefixes << label.rjust(length, ' ')[-length, length]
|
44
|
+
prefixes << ' | '
|
45
|
+
prefixes.join('')
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_thread_count
|
49
|
+
Thread.list.select { |thread| thread.status == 'run' }.count
|
50
|
+
end
|
51
|
+
|
52
|
+
def thread_count
|
53
|
+
Thread.list.count
|
54
|
+
end
|
55
|
+
|
56
|
+
def log_prefix_labels
|
57
|
+
caller.
|
58
|
+
reject { |x| x.index(__FILE__) }.
|
59
|
+
map { |x| x =~ /(.*):(.*):in `(.*)'/ ? [$1, $2, $3] : nil }.
|
60
|
+
first
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug(string)
|
66
|
+
self.class.debug string
|
67
|
+
end
|
68
|
+
|
69
|
+
def debug_var(name, var, meth = :inspect, level = :debug)
|
70
|
+
self.class.debug_var name, var, meth, level
|
71
|
+
end
|
72
|
+
|
73
|
+
def info(string)
|
74
|
+
self.class.info string
|
75
|
+
end
|
76
|
+
|
77
|
+
def warn(string)
|
78
|
+
self.class.warn string
|
79
|
+
end
|
80
|
+
|
81
|
+
def error(string)
|
82
|
+
self.class.error string
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
extend self
|
87
|
+
|
88
|
+
attr_accessor :logger
|
89
|
+
|
90
|
+
self.logger = Logger.new(STDOUT).tap { |x| x.level = Logger::INFO } if logger.nil?
|
91
|
+
|
92
|
+
end
|
data/lib/elected/senado.rb
CHANGED
data/lib/elected/version.rb
CHANGED
data/lib/elected.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elected
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Madrid
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- elected.gemspec
|
115
115
|
- lib/elected.rb
|
116
116
|
- lib/elected/lider.rb
|
117
|
+
- lib/elected/logging.rb
|
117
118
|
- lib/elected/senado.rb
|
118
119
|
- lib/elected/version.rb
|
119
120
|
homepage: https://github.com/simple-finance/elected
|