add timeout
This commit is contained in:
parent
4a564dd07e
commit
1390850e18
1 changed files with 17 additions and 5 deletions
|
@ -11,6 +11,7 @@ module MPW
|
||||||
require 'i18n'
|
require 'i18n'
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
class MPWSync
|
class MPWSync
|
||||||
|
|
||||||
|
@ -37,9 +38,20 @@ module MPW
|
||||||
@password = password
|
@password = password
|
||||||
@suffix = path
|
@suffix = path
|
||||||
|
|
||||||
|
Timeout.timeout(10) do
|
||||||
|
begin
|
||||||
TCPSocket.open(@host, @port) do
|
TCPSocket.open(@host, @port) do
|
||||||
|
puts 'testi2'
|
||||||
@enable = true
|
@enable = true
|
||||||
end
|
end
|
||||||
|
rescue Errno::ENETUNREACH
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
puts 'timeout'
|
||||||
|
@error_msg = "#{I18n.t('error.timeout')}\n#{e}"
|
||||||
|
@enable = false
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
|
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
|
||||||
@enable = false
|
@enable = false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue