villein 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5c615e2b141f002aed95140b94e8df47c7d05f1
4
- data.tar.gz: e1a88330fa171bf6d9e906f3d6d39eaf4c133fc8
3
+ metadata.gz: 2aaa35f865062a4e4d80919f3098dd66c6c0e19f
4
+ data.tar.gz: 9e1a7327b766558819f3481211182626032dc7f3
5
5
  SHA512:
6
- metadata.gz: ad2473ae38e77bdd1b748ab2a6ee2bec54cb36ca0bbc41121cdd47eddeaadd77abb1b9e328375f8d811843e6e35e3aa2e156dd98533bf819dcfe7e0a637e59bb
7
- data.tar.gz: d58a938b086694e1f005c9485301328388a07b5ca2a7b7e0897beb6103cf147bb167ae0ac75ac15d5654752138a314902894bd1b8d764ab4fb06a449dbaa8fdf
6
+ metadata.gz: 2917a0fa0ed13cc0424dab7970e5e270f36569a6951432be0d2469cced125e0a324945ed0c8879c4ff4de807551100645be253293362da3dba376274a059850b
7
+ data.tar.gz: 1900c81bbeb2ff22b927fa8b7ea38f2e43709afd8dd0a9046d5a39eb559031b9c51cf4478a4413861d021f713880bb4cb03091034ce81d7e701dd6624c5031ba
data/.travis.yml CHANGED
@@ -17,7 +17,7 @@ notifications:
17
17
  - travis-ci@sorah.jp
18
18
  before_script:
19
19
  - mkdir -p vendor/serf
20
- - curl -o vendor/serf/serf.zip https://dl.bintray.com/mitchellh/serf/0.5.0_linux_amd64.zip
20
+ - curl -L -o vendor/serf/serf.zip https://dl.bintray.com/mitchellh/serf/0.5.0_linux_amd64.zip
21
21
  - unzip -d vendor/serf vendor/serf/serf.zip
22
22
  - export PATH=$PWD/vendor/serf:$PATH
23
23
  script: bundle exec rspec -fd ./spec
data/lib/villein/agent.rb CHANGED
@@ -54,6 +54,13 @@ module Villein
54
54
  !!@exitstatus
55
55
  end
56
56
 
57
+ ##
58
+ # Return true when the agent has received events at least once.
59
+ # Useful to wait serf for ready to use.
60
+ def ready?
61
+ running? && @event_received
62
+ end
63
+
57
64
  ##
58
65
  # Returns true when the serf agent is running (it has started and not dead yet).
59
66
  def running?
@@ -65,6 +72,8 @@ module Villein
65
72
  @pid_lock.synchronize do
66
73
  raise AlreadyStarted if running?
67
74
 
75
+ @event_received = false
76
+
68
77
  start_listening_events
69
78
  start_process
70
79
  start_watchdog
@@ -91,6 +100,12 @@ module Villein
91
100
  end
92
101
  end
93
102
 
103
+ ##
104
+ # Blocks until #ready? become true.
105
+ def wait_for_ready
106
+ sleep 0.1 until ready?
107
+ end
108
+
94
109
  ##
95
110
  # Add +at_exit+ hook to safely stop at exit of current ruby process.
96
111
  # Note that +Kernel#.at_exit+ hook won't run when Ruby has crashed.
@@ -233,6 +248,8 @@ module Villein
233
248
  event_payload = JSON.parse(json)
234
249
  event = Event.new(event_payload['env'], payload: event_payload['input'])
235
250
 
251
+ @event_received = true
252
+
236
253
  call_hooks event.type.gsub(/-/, '_'), event
237
254
  call_hooks 'event', event
238
255
  rescue JSON::ParserError
@@ -1,3 +1,3 @@
1
1
  module Villein
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/agent_spec.rb CHANGED
@@ -41,9 +41,12 @@ describe Villein::Agent do
41
41
 
42
42
  agent.start!
43
43
 
44
+ Thread.new { agent.wait_for_ready }.join(5)
45
+
44
46
  expect(agent.dead?).to be_false
45
47
  expect(agent.running?).to be_true
46
48
  expect(agent.started?).to be_true
49
+ expect(agent.ready?).to be_true
47
50
  expect(agent.pid).to be_a(Fixnum)
48
51
 
49
52
  agent.stop!
@@ -51,6 +54,7 @@ describe Villein::Agent do
51
54
  expect(agent.dead?).to be_false
52
55
  expect(agent.running?).to be_false
53
56
  expect(agent.started?).to be_false
57
+ expect(agent.ready?).to be_false
54
58
  expect(agent.pid).to be_nil
55
59
 
56
60
  expect(received).to eq [true, nil]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: villein
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Fukumori (sora_h)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec