Retry mailserver request when initial request fails

If the initial request fails we immediately show the error pop-up. This
PR changes the behavior so that it is retried just like any other
request. If 3 requests in a row fail, we show the error pop up if the
user has specifically set a mailserver, otherwise is changed
automatically.

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Andrea Maria Piana 2019-02-21 12:24:38 +01:00 committed by Igor Mandrigin
parent ceebbc8795
commit c56ef18ca9
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
2 changed files with 11 additions and 3 deletions

View File

@ -371,6 +371,11 @@
(fn [cofx [_ _ url]]
(mailserver/set-url-from-qr cofx url)))
(handlers/register-handler-fx
:mailserver.callback/resend-request
(fn [cofx [_ request]]
(mailserver/resend-request cofx request)))
(handlers/register-handler-fx
:mailserver.ui/connect-pressed
(fn [cofx [_ mailserver-id]]

View File

@ -40,6 +40,7 @@
(def request-timeout 30)
(def min-limit 200)
(def max-limit 2000)
(def backoff-interval-ms 3000)
(def default-limit max-limit)
(def connection-timeout
"Time after which mailserver connection is considered to have failed"
@ -290,7 +291,8 @@
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
(do
(log/error "mailserver: messages request error for topic " topics ": " error)
(re-frame/dispatch [:mailserver.callback/request-error (i18n/label :t/mailserver-request-error-title)])))))))
(utils/set-timeout #(re-frame/dispatch [:mailserver.callback/resend-request {:request-id "failed-request"}])
backoff-interval-ms)))))))
(re-frame/reg-fx
:mailserver/request-messages
@ -572,8 +574,9 @@
(fx/defn resend-request
[{:keys [db] :as cofx} {:keys [request-id]}]
(if (<= maximum-number-of-attempts
(get-in db [:mailserver/current-request :attempts]))
(if (and (:mailserver/current-request db)
(<= maximum-number-of-attempts
(get-in db [:mailserver/current-request :attempts])))
(fx/merge cofx
{:db (update db :mailserver/current-request dissoc :attempts)}
(change-mailserver))