nobject 1.1.18 → 1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nobject/local.rb +52 -28
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 735417071860a888e86bb652a14f147bdca25d66add3b2cb6d09509e4f6c05ad
4
- data.tar.gz: d5462edfd3224e520907f0b7c3323ff00bb3654cf4103c3170c8f0e5074f3c51
3
+ metadata.gz: 17e292f75e9f260c1c4d1183f5ad12749fa74b98f5de313ee89cb8c9bfe99935
4
+ data.tar.gz: a83497c75a0280157b671fd84005c0ea0410d25e5fec4b535b6db26389c110c3
5
5
  SHA512:
6
- metadata.gz: 8096bc14015f9604f9b594844cf3c96b2a1452a89c93ef0334d921a6cc0d9ffc6caf5f6dc5e8f98065ae9ab2568a3a1297002e0724af279c3f97d9b4df6d2c4b
7
- data.tar.gz: ecbd98324b162bbb7b7bd2ed051411a06b5df8334717282e3ac9c8cf53f1a90f56840055865242580b16e368f4aa5eb89a1cd4b75f60a20c6a45f62d69fc1e59
6
+ metadata.gz: 6b3a073baec24f5cf52d1e6100e6104c646efe0f6de803dd02f2833979de36b9ae7d3bbedc10cab942515e636f7b41f359e5617c6d0404159316116b41d71cea
7
+ data.tar.gz: 22f333104e7546330883519361c80c4b287bb3a8402d647ebee0dc39ea42e6523b8c876ee8d6286eee609d9b85710b4b3ea2d6b96a4aab52ee152149e648e1ff
data/lib/nobject/local.rb CHANGED
@@ -5,6 +5,8 @@ module Nobject
5
5
  # it to a Nobject::Serve4r, which will then send method calls to a matching
6
6
  # Nobject::Remote object
7
7
  class Local
8
+ MAX_RETRIES = 3
9
+
8
10
  # host: the hostname of the server to push obj to
9
11
  # port: the port number of the server to push obj to
10
12
  # obj: the obj to store over the network
@@ -29,36 +31,57 @@ module Nobject
29
31
  msg = { method: method, args: args }
30
32
  msg_bytes = Marshal.dump(msg)
31
33
 
32
- begin
33
- @socket.send([msg_bytes.length].pack('Q>'), 0)
34
- File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMS:##{@msg_counter += 1} sz#{msg_bytes.length} m:#{method}"; f.flush }
35
- @socket.send(msg_bytes, 0)
36
- @socket.flush
37
- rescue Exception
38
- raise Local::MethodRequestFailure.new("did not receive response from call to `#{method}' over the network")
39
- end
34
+ retries = 0
35
+ loop do
36
+ raise MethodInvocationRetriesExceeded.new("Exceeded retry limit (#{MAX_RETRIES})") if retries == MAX_RETRIES
37
+
38
+ begin
39
+ @socket.send([msg_bytes.length].pack('Q>'), 0)
40
+ File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMS:##{@msg_counter += 1} sz#{msg_bytes.length} m:#{method}"; f.flush }
41
+ @socket.send(msg_bytes, 0)
42
+ @socket.flush
43
+ rescue Exception
44
+ raise Local::MethodRequestFailure.new("did not receive response from call to `#{method}' over the network")
45
+ end
46
+
47
+ return_data = begin
48
+ msg_size = @socket.recv(8).unpack('Q>').first
49
+ raw_bytes = @socket.recv(msg_size)
50
+ File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMGotit :##{@msg_counter += 1} sz#{msg_size} bytes:#{raw_bytes.length} m:#{method}"; f.flush }
51
+ if msg_size != raw_bytes.length
52
+ retries += 1
53
+ print "\a" # TODO: consider removing this after the
54
+ # retry logic seems solid, it's extra,
55
+ # literal noise :)
56
+ redo
57
+ end
40
58
 
41
- return_data = begin
42
- msg_size = @socket.recv(8).unpack('Q>').first
43
- raw_bytes = @socket.recv(msg_size)
44
- File.open('/tmp/nobject.log', 'a') {|f| f.puts " LMGotit :##{@msg_counter += 1} sz#{msg_size} bytes:#{raw_bytes.length} m:#{method}"; f.flush }
45
- Marshal.load(raw_bytes)
46
- rescue Exception => e
47
- error_msg = <<~MSG
48
- did not receive response from call to `#{method}' over the network
49
- would have been msg_id #{@msg_counter} OR #{@msg_counter + 1} when trying to receive #{msg_size} bytes
50
- caused by #{e.class.name}
51
- exception backtrace:
52
- #{e.backtrace.join("\n ")}
53
- MSG
54
- raise Local::MethodResponseFailure.new(error_msg)
55
- end
59
+ Marshal.load(raw_bytes)
60
+ rescue Exception => e
61
+ # TODO: consider removing this rescue block:
62
+ # this rescue may be unreachable now, since the only
63
+ # time it used to happen was when:
64
+ # msg_size != raw_bytes.length
65
+ #
66
+ # ... which is now handled by the retry logic above
67
+ error_msg = <<~MSG
68
+ did not receive response from call to `#{method}' over the network
69
+ would have been msg_id #{@msg_counter} OR #{@msg_counter + 1} when trying to receive #{msg_size} bytes
70
+ caused by #{e.class.name}
71
+ exception backtrace:
72
+ #{e.backtrace.join("\n ")}
73
+ MSG
74
+ raise Local::MethodResponseFailure.new(error_msg)
75
+ end
56
76
 
57
- case return_data.first
58
- when :ok then return_data.last
59
- when :raise then raise return_data.last
60
- else
61
- raise Local::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within Nobject::Local (Nobject::Local::UnknownReturnDataType)")
77
+ break (
78
+ case return_data.first
79
+ when :ok then return_data.last
80
+ when :raise then raise return_data.last
81
+ else
82
+ raise Local::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within Nobject::Local (Nobject::Local::UnknownReturnDataType)")
83
+ end
84
+ )
62
85
  end
63
86
  end
64
87
 
@@ -77,4 +100,5 @@ module Nobject
77
100
  class Local::InvalidMethod < RuntimeError; end
78
101
  class Local::MethodRequestFailure < RuntimeError; end
79
102
  class Local::MethodResponseFailure < RuntimeError; end
103
+ class Local::MethodInvocationRetriesExceeded < RuntimeError; end
80
104
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nobject
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.18
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-01 00:00:00.000000000 Z
10
+ date: 2025-05-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: network-hosted objects that you can call methods on as if they were local
13
13
  email: jefflunt@gmail.com