attention 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/attention.gemspec +3 -1
- data/lib/attention.rb +0 -1
- data/lib/attention/instance.rb +8 -5
- data/lib/attention/version.rb +1 -1
- metadata +33 -6
- data/lib/attention/timer.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afeb250d478f294f9f153c598f9d198dc25114c5
|
4
|
+
data.tar.gz: 86e3566582dbac6d8e738a4c96c7b11630b54c86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acdbf5c64e70a65ad2e6f76adf8e9e863b564932bafca4700a46776a13091184e919b5fa0ac838d64f5002d1cf5729098d7dd6cf5c255bbf0af359a7a24d911d
|
7
|
+
data.tar.gz: fc294d634ea642cc40945192839b996971deb48881d83a71f732308c25ca215b96737dfcc6b7bba2bce77aa295888c4a200d35ffca0b35674b38ec4debb5c0d9
|
data/attention.gemspec
CHANGED
@@ -19,11 +19,13 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
+
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0.2'
|
23
|
+
spec.add_runtime_dependency 'concurrent-ruby-ext', '~> 1.0.2'
|
22
24
|
spec.add_runtime_dependency 'redis', '~> 3'
|
23
25
|
spec.add_runtime_dependency 'redis-namespace', '~> 1.5'
|
24
26
|
spec.add_runtime_dependency 'connection_pool', '~> 2'
|
25
27
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
29
31
|
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
data/lib/attention.rb
CHANGED
data/lib/attention/instance.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'socket'
|
2
|
+
require 'concurrent'
|
2
3
|
require 'attention/publisher'
|
3
|
-
require 'attention/timer'
|
4
4
|
|
5
5
|
module Attention
|
6
6
|
# A publishable representation of the current server
|
@@ -49,10 +49,10 @@ module Attention
|
|
49
49
|
# Unpublishes this server and stops the {#heartbeat}
|
50
50
|
def unpublish
|
51
51
|
return unless @heartbeat
|
52
|
+
@heartbeat.shutdown
|
52
53
|
publisher.publish('instance', removed: info) do |redis|
|
53
54
|
redis.del "instance_#{ @id }"
|
54
55
|
end
|
55
|
-
@heartbeat.stop
|
56
56
|
@heartbeat = nil
|
57
57
|
end
|
58
58
|
|
@@ -67,14 +67,17 @@ module Attention
|
|
67
67
|
|
68
68
|
private
|
69
69
|
|
70
|
-
# Uses a {
|
70
|
+
# Uses a {Concurrent::TimerTask} to periodically tell Redis that this
|
71
71
|
# server is still online
|
72
72
|
# @!visibility public
|
73
73
|
# @api private
|
74
74
|
def heartbeat
|
75
|
-
@heartbeat
|
76
|
-
|
75
|
+
return @heartbeat if @heartbeat
|
76
|
+
@heartbeat = Concurrent::TimerTask.new(execution_interval: heartbeat_frequency) do
|
77
|
+
Attention.redis.call.setex "instance_#{ @id }", Attention.options[:ttl], JSON.dump(info)
|
77
78
|
end
|
79
|
+
@heartbeat.execute
|
80
|
+
@heartbeat
|
78
81
|
end
|
79
82
|
|
80
83
|
# The frequency of the {#heartbeat} is based on Attention.options[:ttl]
|
data/lib/attention/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attention
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: concurrent-ruby-ext
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.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: 1.0.2
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: redis
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +86,14 @@ dependencies:
|
|
58
86
|
requirements:
|
59
87
|
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
89
|
+
version: '1.13'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
96
|
+
version: '1.13'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rake
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,7 +219,6 @@ files:
|
|
191
219
|
- lib/attention/publisher.rb
|
192
220
|
- lib/attention/redis_pool.rb
|
193
221
|
- lib/attention/subscriber.rb
|
194
|
-
- lib/attention/timer.rb
|
195
222
|
- lib/attention/version.rb
|
196
223
|
homepage: https://github.com/parrish/attention
|
197
224
|
licenses:
|
@@ -213,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
240
|
version: '0'
|
214
241
|
requirements: []
|
215
242
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
243
|
+
rubygems_version: 2.5.1
|
217
244
|
signing_key:
|
218
245
|
specification_version: 4
|
219
246
|
summary: Redis-based server awareness
|
data/lib/attention/timer.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
|
-
module Attention
|
4
|
-
# Periodic asynchronous code execution
|
5
|
-
class Timer
|
6
|
-
attr_reader :frequency
|
7
|
-
|
8
|
-
# @!visibility private
|
9
|
-
attr_reader :callback, :lock, :thread
|
10
|
-
|
11
|
-
# Creates and {#start}s the timer
|
12
|
-
# @param frequency [Numeric] How often to execute
|
13
|
-
# @yield The code to be executed
|
14
|
-
def initialize(frequency, &callback)
|
15
|
-
@frequency = frequency
|
16
|
-
@callback = callback
|
17
|
-
@lock = Mutex.new
|
18
|
-
start
|
19
|
-
end
|
20
|
-
|
21
|
-
# Starts the timer
|
22
|
-
def start
|
23
|
-
@thread ||= Thread.new do
|
24
|
-
loop do
|
25
|
-
sleep @frequency
|
26
|
-
lock.synchronize do
|
27
|
-
callback.call
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Boolean] True if the timer is started
|
34
|
-
def started?
|
35
|
-
!!thread
|
36
|
-
end
|
37
|
-
|
38
|
-
# Stops the timer if it's started
|
39
|
-
def stop
|
40
|
-
return if stopped?
|
41
|
-
lock.synchronize do
|
42
|
-
thread.kill
|
43
|
-
@thread = nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [Boolean] True if the timer is stopped
|
48
|
-
def stopped?
|
49
|
-
!started?
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|