Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday timeout #74

Merged
merged 8 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
OpenStudio(R) Analysis Gem Change Log
==================================

Version 1.3.5
-------------
* Increase Timeouts and write_timeouts to deal with latencies for network related issues

Version 1.3.4
-------------
* Update licenses
Expand Down
44 changes: 30 additions & 14 deletions lib/openstudio/analysis/server_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def initialize(options = {})
# create connection with basic capabilities
@conn = Faraday.new(url: @hostname) do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.options.timeout = 300
faraday.options.open_timeout = 300
faraday.options.write_timeout = 1800
faraday.use Faraday::Response::Logger, @logger
# faraday.response @logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
Expand All @@ -40,6 +43,9 @@ def initialize(options = {})
@conn_multipart = Faraday.new(url: @hostname) do |faraday|
faraday.request :multipart
faraday.request :url_encoded # form-encode POST params
faraday.options.timeout = 300
faraday.options.open_timeout = 300
faraday.options.write_timeout = 1800
faraday.use Faraday::Response::Logger, @logger
# faraday.response :logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
Expand Down Expand Up @@ -97,13 +103,17 @@ def new_project(options = {})

# TODO: make this a display name and a machine name
project_hash = { project: { name: (options[:project_name]).to_s } }

response = @conn.post do |req|
req.url '/projects.json'
req.headers['Content-Type'] = 'application/json'
req.body = project_hash.to_json
begin
response = @conn.post do |req|
req.url '/projects.json'
req.headers['Content-Type'] = 'application/json'
req.body = project_hash.to_json
end
puts "response.status: #{response.status}"
puts response.inspect
rescue Net::OpenTimeout => e
puts "new_project OpenTimeout: #{e.message}"
end

if response.status == 201
project_id = JSON.parse(response.body)['_id']

Expand Down Expand Up @@ -204,16 +214,19 @@ def machine_status
begin
resp = @conn.get do |req|
req.url 'status.json'
req.options.timeout = 120
req.options.open_timeout = 120
req.options.timeout = 300
req.options.open_timeout = 300
end

puts "machine_status resp.status: #{resp.status}"
puts resp.inspect
if resp.status == 200
j = JSON.parse resp.body, symbolize_names: true
status = j if j
end
rescue Faraday::ConnectionFailed
rescue Net::ReadTimeout
rescue Faraday::ConnectionFailed => e
puts "machine_Status ConnectionFailed: #{e.message}"
rescue Net::ReadTimeout => e
puts "machine_Status ReadTimeout: #{e.message}"
end

status
Expand Down Expand Up @@ -466,7 +479,8 @@ def new_analysis(project_id, options)
req.url "projects/#{project_id}/analyses.json"
req.headers['Content-Type'] = 'application/json'
req.body = formulation_json.to_json
req.options[:timeout] = 600 # seconds
req.options.timeout = 600 # seconds
req.options.write_timeout = 1800
end

if response.status == 201
Expand All @@ -486,7 +500,8 @@ def new_analysis(project_id, options)

payload = { file: Faraday::UploadIO.new(options[:upload_file], 'application/zip') }
response = @conn_multipart.post "analyses/#{analysis_id}/upload.json", payload do |req|
req.options[:timeout] = 1800 # seconds
req.options.timeout = 1800 # seconds
req.options.write_timeout = 1800
end

if response.status == 201
Expand Down Expand Up @@ -632,7 +647,8 @@ def start_analysis(analysis_id, options)
req.url "analyses/#{analysis_id}/action.json"
req.headers['Content-Type'] = 'application/json'
req.body = options.to_json
req.options[:timeout] = 1800 # seconds
req.options.timeout = 1800 # seconds
req.options.write_timeout = 1800
end

if response.status == 200
Expand Down
2 changes: 1 addition & 1 deletion lib/openstudio/analysis/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module OpenStudio
module Analysis
# format should be ^.*\-{1}[a-z]+[0-9]+
# for example: -rc1, -beta6, -customusecase0
VERSION = '1.3.4'.freeze
VERSION = '1.3.5'.freeze
end
end
Loading