utils/sync_demoddata_to_db: Raise RequestException if sync fails (W0703)
Let the caller handle the exception in case the sync fails. Fixes a broad-except (W0703) pylint error. Signed-off-by: Fabian P. Schmidt <kerel@mailbox.org>merge-requests/849/head
parent
426e3585f8
commit
f774025a6f
|
@ -4,6 +4,7 @@ from __future__ import absolute_import
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.timezone import now
|
||||
from requests.exceptions import RequestException
|
||||
from rest_framework import mixins, status, viewsets
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import ValidationError
|
||||
|
@ -80,7 +81,11 @@ class ObservationView( # pylint: disable=R0901
|
|||
except ObjectDoesNotExist:
|
||||
demoddata = instance.demoddata.create(payload_demod=request.data.get('demoddata'))
|
||||
if Transmitter.objects.get(uuid=instance.transmitter_uuid).sync_to_db:
|
||||
sync_demoddata_to_db(demoddata.id)
|
||||
try:
|
||||
sync_demoddata_to_db(demoddata.id)
|
||||
except RequestException:
|
||||
# Sync to db failed, let the periodic task handle the sync to db later
|
||||
pass
|
||||
if request.data.get('waterfall'):
|
||||
if instance.has_waterfall:
|
||||
return Response(
|
||||
|
|
|
@ -190,11 +190,13 @@ def sync_to_db():
|
|||
copied_to_db=False, observation__transmitter_uuid__in=transmitters
|
||||
)
|
||||
for frame in frames:
|
||||
if frame.is_image() or frame.copied_to_db or not os.path.isfile(frame.payload_demod.path):
|
||||
continue
|
||||
|
||||
try:
|
||||
if not frame.is_image() and not frame.copied_to_db:
|
||||
if os.path.isfile(frame.payload_demod.path):
|
||||
sync_demoddata_to_db(frame.id)
|
||||
except Exception:
|
||||
sync_demoddata_to_db(frame.id)
|
||||
except requests.exceptions.RequestException:
|
||||
# Sync to db failed, skip this frame for a future task instance
|
||||
continue
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,10 @@ def export_station_status(self, request, queryset):
|
|||
|
||||
|
||||
def sync_demoddata_to_db(frame_id):
|
||||
"""Task to send a frame from SatNOGS Network to SatNOGS DB"""
|
||||
"""
|
||||
Task to send a frame from SatNOGS Network to SatNOGS DB
|
||||
|
||||
Raises requests.exceptions.RequestException if sync fails."""
|
||||
frame = DemodData.objects.get(id=frame_id)
|
||||
obs = frame.observation
|
||||
sat = obs.satellite
|
||||
|
@ -100,15 +103,11 @@ def sync_demoddata_to_db(frame_id):
|
|||
|
||||
telemetry_url = "{}telemetry/".format(settings.DB_API_ENDPOINT)
|
||||
|
||||
try:
|
||||
response = requests.post(telemetry_url, data=params)
|
||||
response.raise_for_status()
|
||||
response = requests.post(telemetry_url, data=params, timeout=settings.DB_API_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
|
||||
frame.copied_to_db = True
|
||||
frame.save()
|
||||
except requests.exceptions.RequestException:
|
||||
# Sync to db failed
|
||||
pass
|
||||
frame.copied_to_db = True
|
||||
frame.save()
|
||||
|
||||
|
||||
def community_get_discussion_details(
|
||||
|
|
Loading…
Reference in New Issue