Skip to content

Commit

Permalink
app: use ServerConnectionError from SDK 0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Feb 12, 2020
1 parent 6b09720 commit 25aeb2c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ python-editor==1.0.3 \
requests==2.20.0 \
--hash=sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c \
--hash=sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279
securedrop-sdk==0.0.12 \
--hash=sha256:b5ddca26ce87d4007db5d64fe77d44b4086a902c3f79e69fb9a81343c81ce278
securedrop-sdk==0.0.13 \
--hash=sha256:3d521e7a63cd7df55f9c6508010f968692eccdb222c57ed9c2d0390fbbbd6f99 \
--hash=sha256:7763bb44755bdfc387ab6c002cbe49eeec2611feb04a8787c3c9f2aa48a1ee5f
sip==4.19.8 \
--hash=sha256:09f9a4e6c28afd0bafedb26ffba43375b97fe7207bd1a0d3513f79b7d168b331 \
--hash=sha256:105edaaa1c8aa486662226360bd3999b4b89dd56de3e314d82b83ed0587d8783 \
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pathlib2==2.3.2
python-dateutil==2.7.5
python-editor==1.0.3
requests==2.20.0
securedrop-sdk==0.0.12
securedrop-sdk==0.0.13
six==1.11.0
SQLAlchemy==1.3.3
urllib3==1.24.3
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ python-editor==1.0.3 \
requests==2.20.0 \
--hash=sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c \
--hash=sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279
securedrop-sdk==0.0.12 \
--hash=sha256:b5ddca26ce87d4007db5d64fe77d44b4086a902c3f79e69fb9a81343c81ce278
securedrop-sdk==0.0.13 \
--hash=sha256:3d521e7a63cd7df55f9c6508010f968692eccdb222c57ed9c2d0390fbbbd6f99 \
--hash=sha256:7763bb44755bdfc387ab6c002cbe49eeec2611feb04a8787c3c9f2aa48a1ee5f
six==1.11.0 \
--hash=sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9 \
--hash=sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb
Expand Down
4 changes: 2 additions & 2 deletions securedrop_client/api_jobs/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from PyQt5.QtCore import QObject, pyqtSignal
from sdclientapi import API, AuthError, RequestTimeoutError
from sdclientapi import API, AuthError, RequestTimeoutError, ServerConnectionError
from sqlalchemy.orm.session import Session
from typing import Any, Optional, TypeVar

Expand Down Expand Up @@ -71,7 +71,7 @@ def _do_call_api(self, api_client: API, session: Session) -> None:
result = self.call_api(api_client, session)
except (AuthError, ApiInaccessibleError) as e:
raise ApiInaccessibleError() from e
except RequestTimeoutError as e:
except (RequestTimeoutError, ServerConnectionError) as e:
if self.remaining_attempts == 0:
self.failure_signal.emit(e)
raise
Expand Down
4 changes: 2 additions & 2 deletions securedrop_client/api_jobs/uploads.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sdclientapi

from sdclientapi import API, RequestTimeoutError
from sdclientapi import API, RequestTimeoutError, ServerConnectionError
from sqlalchemy.orm.session import Session

from securedrop_client.api_jobs.base import ApiJob
Expand Down Expand Up @@ -65,7 +65,7 @@ def call_api(self, api_client: API, session: Session) -> str:
session.commit()

return reply_db_object.uuid
except RequestTimeoutError as e:
except (RequestTimeoutError, ServerConnectionError) as e:
message = "Failed to send reply for source {id} due to Exception: {error}".format(
id=self.source_uuid, error=e)

Expand Down
4 changes: 2 additions & 2 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from gettext import gettext as _
from PyQt5.QtCore import QObject, QThread, pyqtSignal, QTimer, QProcess, Qt
from sdclientapi import RequestTimeoutError
from sdclientapi import RequestTimeoutError, ServerConnectionError
from sqlalchemy.orm.session import sessionmaker

from securedrop_client import storage
Expand Down Expand Up @@ -98,7 +98,7 @@ def call_api(self):
try:
self.result = self.api_call(*self.args, **self.kwargs)
except Exception as ex:
if isinstance(ex, RequestTimeoutError):
if isinstance(ex, (RequestTimeoutError, ServerConnectionError)):
self.call_timed_out.emit()

logger.error(ex)
Expand Down
14 changes: 7 additions & 7 deletions securedrop_client/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from PyQt5.QtCore import QObject, QThread, pyqtSlot, pyqtSignal
from queue import PriorityQueue
from sdclientapi import API, RequestTimeoutError
from sdclientapi import API, RequestTimeoutError, ServerConnectionError
from sqlalchemy.orm import scoped_session
from typing import Optional, Tuple # noqa: F401

Expand All @@ -26,10 +26,10 @@ class RunnableQueue(QObject):
job type. If multiple jobs of the same type are added to the queue then they are retrieved
in FIFO order.
If a RequestTimeoutError is encountered while processing a job, the job will be added back to
the queue, the processing loop will stop, and the paused signal will be emitted. New jobs can
still be added, but the processing function will need to be called again in order to resume. The
processing loop is resumed when the resume signal is emitted.
If a RequestTimeoutError or ServerConnectionError is encountered while processing a job, the
job will be added back to the queue, the processing loop will stop, and the paused signal will
be emitted. New jobs can still be added, but the processing function will need to be called
again in order to resume. The processing loop is resumed when the resume signal is emitted.
If an ApiInaccessibleError is encountered while processing a job, api_client will be set to
None and the processing loop will stop. If the queue is resumed before the queue manager
Expand Down Expand Up @@ -97,7 +97,7 @@ def process(self) -> None:
If the job is a PauseQueueJob, emit the paused signal and return from the processing loop so
that no more jobs are processed until the queue resumes.
If the job raises RequestTimeoutError, then:
If the job raises RequestTimeoutError or ServerConnectionError, then:
(1) Add a PauseQueuejob to the queue
(2) Add the job back to the queue so that it can be reprocessed once the queue is resumed.
Expand All @@ -123,7 +123,7 @@ def process(self) -> None:
logger.debug('{}: {}'.format(type(e).__name__, e))
self.api_client = None
return
except RequestTimeoutError as e:
except (RequestTimeoutError, ServerConnectionError) as e:
logger.debug('{}: {}'.format(type(e).__name__, e))
self.add_job(PauseQueueJob())
self.re_add_job(job)
Expand Down
4 changes: 2 additions & 2 deletions securedrop_client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from PyQt5.QtCore import pyqtSignal, QObject, QThread, QTimer, Qt
from sqlalchemy.orm import scoped_session
from sdclientapi import API, RequestTimeoutError
from sdclientapi import API, RequestTimeoutError, ServerConnectionError

from securedrop_client.api_jobs.base import ApiInaccessibleError
from securedrop_client.api_jobs.sync import MetadataSyncJob
Expand Down Expand Up @@ -75,7 +75,7 @@ def on_sync_failure(self, result: Exception) -> None:
Only start another sync on failure if the reason is a timeout request.
'''
self.sync_failure.emit(result)
if isinstance(result, RequestTimeoutError):
if isinstance(result, (RequestTimeoutError, ServerConnectionError)):
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self.api_sync_bg_task.sync)


Expand Down

0 comments on commit 25aeb2c

Please sign in to comment.