From aa3ff5273ec65081fcdbdfc8dce245aa253dc2dd Mon Sep 17 00:00:00 2001 From: raphaelrpl Date: Mon, 10 Feb 2020 10:13:13 -0300 Subject: [PATCH 1/2] Set rollback on AWS when transaction error --- .../collections/landsat/tasks.py | 15 ++++++++++++--- .../collections/sentinel/tasks.py | 14 +++++++++++--- bdc_collection_builder/version.py | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bdc_collection_builder/collections/landsat/tasks.py b/bdc_collection_builder/collections/landsat/tasks.py index e8dd656..4691641 100644 --- a/bdc_collection_builder/collections/landsat/tasks.py +++ b/bdc_collection_builder/collections/landsat/tasks.py @@ -5,7 +5,6 @@ # 3rdparty from glob import glob as resource_glob -from psycopg2 import InternalError from requests import get as resource_get from sqlalchemy.exc import InvalidRequestError @@ -17,6 +16,7 @@ from bdc_collection_builder.collections.landsat.download import download_landsat_images from bdc_collection_builder.collections.landsat.publish import publish from bdc_collection_builder.collections.utils import get_task_activity +from bdc_collection_builder.db import db_aws class LandsatTask(RadcorTask): @@ -78,8 +78,17 @@ def publish(self, scene): try: assets = publish(self.get_collection_item(activity_history.activity), activity_history.activity) + except InvalidRequestError as e: + # Error related with Transacion on AWS + # TODO: Is it occurs on local instance? + logging.error("Transaction Error on activity - {}".format(activity_history.activity_id), exc_info=True) + + db_aws.session.rollback() + + raise e + except BaseException as e: - logging.error('An error occurred during task execution', e) + logging.error("An error occurred during task execution - {}".format(activity_history.activity_id), exc_info=True) raise e @@ -171,7 +180,7 @@ def atm_correction_landsat(scene): return atm_correction_landsat.correction(scene) -@celery_app.task(base=LandsatTask, queue='publish', max_retries=3, autoretry_for=(InternalError, InvalidRequestError,), default_retry_delay=Config.TASK_RETRY_DELAY) +@celery_app.task(base=LandsatTask, queue='publish', max_retries=3, autoretry_for=(InvalidRequestError,), default_retry_delay=Config.TASK_RETRY_DELAY) def publish_landsat(scene): return publish_landsat.publish(scene) diff --git a/bdc_collection_builder/collections/sentinel/tasks.py b/bdc_collection_builder/collections/sentinel/tasks.py index 9641ffa..a6dfa59 100644 --- a/bdc_collection_builder/collections/sentinel/tasks.py +++ b/bdc_collection_builder/collections/sentinel/tasks.py @@ -10,7 +10,6 @@ from zipfile import ZipFile # 3rdparty -from psycopg2 import InternalError from requests.exceptions import ConnectionError, HTTPError from sqlalchemy.exc import InvalidRequestError @@ -27,6 +26,7 @@ from bdc_collection_builder.collections.sentinel.download import download_sentinel_images, download_sentinel_from_creodias from bdc_collection_builder.collections.sentinel.publish import publish from bdc_collection_builder.collections.sentinel.correction import correction_sen2cor255, correction_sen2cor280 +from bdc_collection_builder.db import db_aws lock = lock_handler.lock('sentinel_download_lock_4') @@ -226,8 +226,16 @@ def publish(self, scene): try: assets = publish(self.get_collection_item(activity_history.activity), activity_history.activity) + except InvalidRequestError as e: + # Error related with Transacion on AWS + # TODO: Is it occurs on local instance? + logging.error("Transaction Error on activity - {}".format(activity_history.activity_id), exc_info=True) + + db_aws.session.rollback() + + raise e except BaseException as e: - logging.error('An error occurred during task execution', e) + logging.error('An error occurred during task execution - {}'.format(activity_history.activity_id), exc_info=True) raise e # Create new activity 'uploadS2' to continue task chain @@ -291,7 +299,7 @@ def atm_correction(scene): return atm_correction.correction(scene) -@celery_app.task(base=SentinelTask, queue='publish', max_retries=3, autoretry_for=(InternalError, InvalidRequestError,), default_retry_delay=Config.TASK_RETRY_DELAY) +@celery_app.task(base=SentinelTask, queue='publish', max_retries=3, autoretry_for=(InvalidRequestError,), default_retry_delay=Config.TASK_RETRY_DELAY) def publish_sentinel(scene): """ Represents a celery task definition for handling Sentinel diff --git a/bdc_collection_builder/version.py b/bdc_collection_builder/version.py index fbbd362..fc88993 100644 --- a/bdc_collection_builder/version.py +++ b/bdc_collection_builder/version.py @@ -1 +1 @@ -__version__ = '0.1.0' +__version__ = '0.2.0' From e478e092f683c3c7ba8557bb2599de55ba117d4b Mon Sep 17 00:00:00 2001 From: raphaelrpl Date: Mon, 10 Feb 2020 10:13:57 -0300 Subject: [PATCH 2/2] Temporary workaround with flask werkzeug dependency error --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 30f263f..fdedb86 100644 --- a/setup.py +++ b/setup.py @@ -42,6 +42,8 @@ 'bdc-db @ git+git://github.com/brazil-data-cube/bdc-db.git#egg=bdc-db', 'stac @ git+git://github.com/brazil-data-cube/stac.py.git#egg=stac', 'celery[librabbitmq]>=4.3.0', + # TODO: Remove werkzeug dependency when https://github.com/noirbizarre/flask-restplus/issues/777 is fixed + 'Werkzeug>=0.16,<1.0' ] g = {}