kosmonaut 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,8 @@
1
+ 2012-01-16 Krzysztof Kowalik <chris@nu7hat.ch>
2
+
3
+ * lib/kosmonaut/socket.rb: base for worker and client
4
+ * lib/kosmonaut/worker.rb: majordomo worker
5
+ * lib/kosmonaut/client.rb: majordomo client
6
+ * lib/kosmonaut/errors.rb: possible protocol errors
7
+ * lib/kosmonaut.rb: base tools
8
+ * test/: tests for client and worker api
data/NEWS ADDED
@@ -0,0 +1,8 @@
1
+ Releases
2
+ ========
3
+
4
+ v0.2.0
5
+ ------
6
+ * Pure ruby implementation of the client and worker using
7
+ majordomo pattern.
8
+ * Tests for the API
data/README CHANGED
@@ -1,5 +1,5 @@
1
- Ruby wrapper for Kosmonaut - the WebRocket client
2
- =================================================
1
+ Kosmonaut - ruby client for the WebRocket
2
+ =========================================
3
3
 
4
4
  Kosmonaut.rb is a ruby backend client for the WebRocket.
5
5
  The idea of the Kosmonaut is to keep it simple, straightforward
data/kosmonaut.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "kosmonaut"
6
- s.version = "0.2.0"
6
+ s.version = "0.2.1"
7
7
  s.summary = "Ruby client for the WebRocket backend"
8
8
  s.description = "The WebRocket server backend client for ruby programming language"
9
9
  s.authors = ["Krzysztof Kowalik", "Cubox"]
@@ -11,9 +11,10 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://webrocket.io/"
12
12
  s.license = "MIT"
13
13
 
14
- s.files = Dir["{lib/**/*.rb,test/*.rb,Rakefile,README*,COPYING,*.gemspec}"]
14
+ s.files = Dir["{lib/**/*.rb,test/*.rb,Rakefile,README,COPYING,NEWS,ChangeLog,*.gemspec}"]
15
15
  s.test_files = Dir["test/*.rb"]
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_dependency "json", "~> 1.0"
19
+ s.add_development_dependency "minitest", "~> 2.0"
19
20
  end
@@ -7,7 +7,6 @@ module Kosmonaut
7
7
 
8
8
  RECONNECT_DELAY = 1000 # in milliseconds
9
9
  HEARTBEAT_INTERVAL = 2000 # in milliseconds
10
- LIVENESS = 3
11
10
 
12
11
  def initialize(url)
13
12
  super(url)
@@ -17,26 +16,27 @@ module Kosmonaut
17
16
  @reconnect_delay = RECONNECT_DELAY
18
17
  @heartbeat_ivl = HEARTBEAT_INTERVAL
19
18
  @heartbeat_at = 0
20
- @liveness = 0
21
19
  end
22
20
 
23
21
  def listen
24
- reconnect
25
22
  @alive = true
23
+ reconnect
26
24
  while true
27
- if !alive?
28
- send(@sock, ["QT"])
29
- disconnect
30
- break
31
- end
32
25
  begin
26
+ if !alive?
27
+ send(@sock, ["QT"]) if @sock
28
+ disconnect
29
+ break
30
+ end
31
+ unless @sock
32
+ raise Errno::ECONNREFUSED
33
+ end
33
34
  Timeout.timeout(((@heartbeat_ivl * 2).to_f / 1000.0).to_i + 1) {
34
35
  msg = recv(@sock)
35
- @liveness = LIVENESS
36
+ raise Errno::ECONNRESET if @sock.eof? || msg.empty?
36
37
  log("Worker/RECV : #{msg.join("\n").inspect}")
37
- next if msg.size < 1
38
38
  cmd = msg.shift
39
-
39
+
40
40
  case cmd
41
41
  when "HB"
42
42
  # nothing to do...
@@ -49,13 +49,12 @@ module Kosmonaut
49
49
  error_handler(msg.size < 1 ? 597 : msg[0])
50
50
  end
51
51
  }
52
- rescue Timeout::Error, Errno::ECONNRESET
53
- if (@liveness -= 1) == 0
54
- sleep(@reconnect_delay.to_f / 1000.0)
55
- reconnect
56
- end
52
+ rescue Timeout::Error, Errno::ECONNRESET, Errno::ECONNREFUSED => err
53
+ log("Worker/RECONNECT: " + err.to_s)
54
+ sleep(@reconnect_delay.to_f / 1000.0)
55
+ reconnect
57
56
  end
58
- if Time.now.to_f > @heartbeat_at
57
+ if Time.now.to_f > @heartbeat_at && @sock
59
58
  send(@sock, ["HB"])
60
59
  @heartbeat_at = Time.now.to_f + (@heartbeat_ivl.to_f / 1000.0)
61
60
  end
@@ -92,9 +91,9 @@ module Kosmonaut
92
91
  def reconnect
93
92
  disconnect
94
93
  @sock = connect
95
- @sock.write(pack(["RD"]))
96
- @liveness = LIVENESS
97
- @heartbeat_at = Time.now.to_f + (@heartbeat_ivl.to_f / 1000.0)
94
+ send(@sock, ["RD"])
95
+ @heartbeat_at = Time.now.to_f + (@heartbeat_ivl.to_f / 1000.0)
96
+ rescue Errno::ECONNREFUSED
98
97
  end
99
98
 
100
99
  def message_handler(data)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosmonaut
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Krzysztof Kowalik
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-01-16 00:00:00 Z
14
+ date: 2012-01-17 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -24,6 +24,17 @@ dependencies:
24
24
  version: "1.0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "2.0"
36
+ type: :development
37
+ version_requirements: *id002
27
38
  description: The WebRocket server backend client for ruby programming language
28
39
  email: chris@nu7hat.ch
29
40
  executables: []
@@ -45,6 +56,8 @@ files:
45
56
  - Rakefile
46
57
  - README
47
58
  - COPYING
59
+ - NEWS
60
+ - ChangeLog
48
61
  - kosmonaut.gemspec
49
62
  homepage: http://webrocket.io/
50
63
  licenses: