cfsolve 0.1.3-x86_64-linux-gnu → 0.1.5-x86_64-linux-gnu

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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cfsolve
4
- VERSION = "0.1.3"
5
- UPSTREAM_REVISION = "d94de0472bad95dee84fb312f9e39f573f8148eb"
4
+ VERSION = "0.1.5"
5
+ UPSTREAM_REVISION = "82b19a39f8366b02c9eaf54b1c09ce97870ba981"
6
6
  end
data/lib/cfsolve.rb CHANGED
@@ -73,23 +73,34 @@ module Cfsolve
73
73
 
74
74
  request[:configuration] = JSON.parse(@configuration)
75
75
  request[:timeout] = timeout
76
+ Timeout.timeout(timeout, TimeoutError, "The solver exceeded its deadline") do
77
+ attempts = 0
78
+ begin
79
+ attempts += 1
80
+ execute(request)
81
+ rescue UnsupportedError
82
+ retry if attempts < 3
83
+ raise
84
+ end
85
+ end
86
+ end
87
+
88
+ def execute(request)
76
89
  child_input, input = IO.pipe
77
90
  output, child_output = IO.pipe
78
91
  pid = Process.spawn(EXECUTABLE, in: child_input, out: child_output, err: File::NULL)
79
92
  status = nil
80
93
  child_input.close
81
94
  child_output.close
82
- Timeout.timeout(timeout, TimeoutError, "The solver exceeded its deadline") do
83
- input.write(JSON.generate(request))
84
- input.close
85
- result = JSON.parse(output.read)
86
- _, status = Process.wait2(pid)
87
- raise Error, "The solver process failed" unless status.success?
88
- if (error = result["error"])
89
- raise ERRORS.fetch(error.fetch("kind"), Error), error.fetch("message")
90
- end
91
- result
95
+ input.write(JSON.generate(request))
96
+ input.close
97
+ result = JSON.parse(output.read)
98
+ _, status = Process.wait2(pid)
99
+ raise Error, "The solver process failed" unless status.success?
100
+ if (error = result["error"])
101
+ raise ERRORS.fetch(error.fetch("kind"), Error), error.fetch("message")
92
102
  end
103
+ result
93
104
  rescue Errno::ENOENT
94
105
  raise ConfigurationError, "The cfsolve executable is missing; reinstall the gem", cause: nil
95
106
  rescue JSON::ParserError, IOError, Errno::EPIPE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfsolve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Oliver Morgan