Fix timeout.

This commit is contained in:
BoHung Chiu 2021-04-26 09:00:48 +08:00
parent 7bc9261ff9
commit 0e7aa6249b
1 changed files with 13 additions and 1 deletions

View File

@ -358,9 +358,21 @@ namespace :sync_asia_personal_plugins do
AsiaSyncPlugin.sync_college_projects(query_result, user)
end
end
def net_http_get_response(uri,headers={})
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
end
http.read_timeout = (@read_timeout.nil? ? 60 : @read_timeout)
res = http.get((uri.path.blank? ? "/" : uri.path)+(uri.query.blank? ? '' : "?#{uri.query}"))
res.uri = uri
res
end
def get_sync_data(user_id)
uri = URI.parse("https://webap.asia.edu.tw/cfd2020/API/Research/Load")
res = Net::HTTP.get_response(uri + "?#{{:id=> user_id}.to_query}")
@read_timeout = 300
res = net_http_get_response(uri + "?#{{:id=> user_id}.to_query}")
return JSON.parse(res.body,{object_class: AsiaSyncPlugin::SafeHash})
end
end