Есть простой код. Каждый 10 сек отправляет http запрос и получает ответ.
require 'vk-ruby'
app = VK::Application.new(app_id: ------, version: '5.71', access_token: '--------------------')
check = 0
while true
get = app.vk_call 'messages.getDialogs?count=2'
body = get['items'][0]['message']['body']
if body != check
p body
check = body
end
sleep 10
end
Но периодически вылетает ошибка и программа закрывается
spoiler/usr/lib/ruby/2.3.0/net/http.rb:880:in `initialize': execution expired (Faraday::ConnectionFailed)
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `open'
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:38:in `block in call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:85:in `with_net_http_connection'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/adapter/net_http.rb:33:in `call'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/middlewares/http_errors.rb:8:in `call'
from /var/lib/gems/2.3.0/gems/faraday_middleware-0.12.2/lib/faraday_middleware/response_middleware.rb:31:in `call'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/middlewares/api_errors.rb:8:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/request/url_encoded.rb:15:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/request/multipart.rb:15:in `call'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/rack_builder.rb:143:in `build_response'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:387:in `run_request'
from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:175:in `post'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/core.rb:66:in `request'
from /var/lib/gems/2.3.0/gems/vk-ruby-1.0.2/lib/vk-ruby/core.rb:26:in `vk_call'
from redis.rb:17:in `'
Как можно решить данную ситуацию? Или можно ли поставить условие, если вылетит данная ошибка с соединением, то подождать еще секунд 10 и повторить запрос. Как реализовать?