Commit 3b6c773e authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Remove traceback logging (multiline)

Remove flask restful from clearcache
parent e3fcd381
......@@ -13,15 +13,14 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask_restful import Resource
from import_api_app.app import app
import requests
import traceback
from flask.views import MethodView
from requests.auth import HTTPBasicAuth
from import_api_app.app import app
class ClearCache(Resource):
class ClearCache(MethodView):
def __init__(self):
self.logger = app.logger
......@@ -49,8 +48,7 @@ class ClearCache(Resource):
try:
response = requests.get(self.url, headers=self.headers, auth=self.auth)
except Exception as ex:
msg = 'Exception while calling ' + self.url + ': ' + str(ex) + '\n' + \
traceback.format_exc()
msg = 'Exception while calling ' + self.url + ': ' + str(ex)
self.logger.error(msg)
return {
'response': msg,
......
......@@ -14,14 +14,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import uuid
from flask_restful import Resource
from import_api_app.app import app
from kafka import KafkaProducer
import requests
import json
import traceback
import requests
from requests.auth import HTTPBasicAuth
from kafka import KafkaProducer
from flask_restful import Resource
from import_api_app.app import app
class UpdateInstitution(Resource):
......@@ -123,7 +122,7 @@ class UpdateInstitution(Resource):
'topic_value': result
}, 500
except Exception as ex:
msg = f'Unknown Exception ({institution_drupal_uuid}): {ex}\n{traceback.format_exc()}'
msg = f'Unknown Exception ({institution_drupal_uuid}): {ex}'
app.logger.error(msg)
return {
'status': 'FAILURE',
......@@ -168,7 +167,7 @@ class UpdateInstitution(Resource):
except Exception as ex:
msg = f'Unknown Exception ({institution_drupal_uuid}): {ex}. ' \
f'Check logs for more details.'
app.logger.error(f'{msg}\n{traceback.format_exc()}')
app.logger.error(msg)
return {
'status': 'FAILURE',
'topic_key': result.get('field_memobase_id'),
......
......@@ -20,7 +20,6 @@ from import_api_app.app import app
from kafka import KafkaProducer
import requests
import json
import traceback
from kafka.errors import KafkaTimeoutError
from requests.auth import HTTPBasicAuth
......@@ -214,9 +213,7 @@ class UpdateRecordSet(Resource):
'field_teaser_image': drupal_record_set_de['relationships']['field_teaser_image']
}
except LookupError as ex:
msg = 'LookupError for ' + record_set_drupal_uuid + ': ' + str(ex) + '\n' + \
traceback.format_exc() + '\n' + \
'baseRequest: ' + de_drupal_url + '\n'
msg = 'LookupError for ' + record_set_drupal_uuid + ': ' + str(ex)
app.logger.error(msg)
return {
'status': 'FAILURE',
......@@ -224,9 +221,7 @@ class UpdateRecordSet(Resource):
'result_topic_value': result_topic_value
}, 500
except Exception as ex:
msg = 'Exception for ' + record_set_drupal_uuid + ': ' + str(ex) + '\n' + \
traceback.format_exc() + '\n' + \
'baseRequest: ' + de_drupal_url + '\n'
msg = 'Exception for ' + record_set_drupal_uuid + ': ' + str(ex)
app.logger.error(msg)
return {
'status': 'FAILURE',
......@@ -262,7 +257,7 @@ class UpdateRecordSet(Resource):
except Exception as ex:
msg = f'Could not import {result_topic_value.get("field_memobase_id")} ' \
f'(Drupal UUID: {record_set_drupal_id}) (Unknown Exception): ' + str(ex)
app.logger.error(f"{msg}\n{traceback.format_exc()}")
app.logger.error(msg)
return {
'status': 'FAILURE',
'topic_key': result_topic_value.get('field_memobase_id'),
......
......@@ -65,23 +65,23 @@ try:
app.config['tfv-reporting-topic-name'] = os.environ['TFV_REPORTING_TOPIC_NAME']
app.config['env'] = os.environ['ENV']
app.config['NAMESPACE'] = os.environ['NAMESPACE']
app.config['SWAGGER'] = {
'title': 'Memobase Import API',
'version': 'dev',
'uiversion': 3,
'termsOfService': 'http://memobase.ch/de/disclaimer',
'description': 'API to start, stop, manage import processes for '
'memobase. Will be used in the Admin Interface (Drupal).',
'contact': {
'name': 'UB Basel',
'url': 'https://ub.unibas.ch',
'email': 'swissbib-ub@unibas.ch'},
'favicon': '/favicon.ico'}
Swagger(app)
except KeyError as ex:
raise ImportApiError(f'Environment variable {ex} is missing.')
app.config['SWAGGER'] = {
'title': 'Memobase Import API',
'version': 'dev',
'uiversion': 3,
'termsOfService': 'http://memobase.ch/de/disclaimer',
'description': 'API to start, stop, manage import processes for '
'memobase. Will be used in the Admin Interface (Drupal).',
'contact': {
'name': 'UB Basel',
'url': 'https://ub.unibas.ch',
'email': 'swissbib-ub@unibas.ch'},
'favicon': '/favicon.ico'}
Swagger(app)
@app.route("/")
def home():
......@@ -126,7 +126,10 @@ api.add_resource(
'/v1/drupal/delete/institution/<session_id>',
'/v1/drupal/delete/institution/<session_id>/<dryrun>'
)
api.add_resource(ClearCache, '/v1/drupal/clearcache')
api.add_resource(ClearCache, )
app.add_url_rule('/v1/drupal/clearcache',
view_func=ClearCache.as_view('clearcache'))
app.logger.info('Initialized API Resources.')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment