Commit 896f8562 authored by Matthias's avatar Matthias
Browse files

add endpoint for clearing drupal cache

parent 47824aa7
......@@ -23,3 +23,5 @@ topicDrupalExport: 'mb-gi-drupal-export-prod'
tfvReportingTopicName: "mb-di-reporting-prod"
tfvTopicName: "mb-di-data-transform-prod"
clearCacheUrl: "/de/memobase/ingestapi/clear_cache"
\ No newline at end of file
......@@ -23,3 +23,5 @@ topicDrupalExport: 'mb-gi-drupal-export-stage'
tfvReportingTopicName: "mb-di-reporting-stage"
tfvTopicName: "mb-di-data-transform-stage"
clearCacheUrl: "/de/memobase/ingestapi/clear_cache"
\ No newline at end of file
......@@ -23,3 +23,5 @@ topicDrupalExport: 'mb-gi-drupal-export-prod'
tfvReportingTopicName: "mb-di-reporting-prod"
tfvTopicName: "mb-di-data-transform-prod"
clearCacheUrl: "/de/memobase/ingestapi/clear_cache"
\ No newline at end of file
......@@ -12,4 +12,5 @@ data:
DRUPAL_API_URL: {{ .Values.drupalApiUrl }}
TOPIC_CONFIGS: {{ .Values.topicConfigs }}
TOPIC_DRUPAL_EXPORT: {{ .Values.topicDrupalExport }}
CLEAR_CACHE_URL: {{ .Values.clearCacheUrl }}
LOG_LEVEL: "{{ .Values.logLevel }}"
......@@ -12,6 +12,7 @@ from import_api_app.resources.WriteTypeReportToDrupal import WriteTypeReportToDr
# from import_api_app.resources.ReadJobOptionsFromDrupal import ReadJobOptionsFromDrupal
from import_api_app.resources.MonitorDrupalJsonApiInstitution import MonitorDrupalJsonApiInstitution
from import_api_app.resources.MonitorDrupalJsonApiRecordSet import MonitorDrupalJsonApiRecordSet
from import_api_app.resources.ClearCache import ClearCache
from import_api_app.resources.ImportProcessStart import ImportProcessStart
from import_api_app.resources.FetchMappingFile import FetchMappingFile
from import_api_app.resources.DeleteRecord import DeleteRecord
......@@ -116,6 +117,7 @@ def create_app(test_config=None):
'/v1/drupal/delete/institution/<session_id>',
'/v1/drupal/delete/institution/<session_id>/<dryrun>'
)
api.add_resource(ClearCache, '/v1/drupal/clearcache')
# TODO : maybe take that to a configuration (development vs pod running in
# k8s cluster)
......
......@@ -9,4 +9,4 @@ if __name__ == "__main__":
logging.basicConfig(format='%(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
level=numeric_level)
app = create_app()
app.run(host='0.0.0.0', debug=False)
app.run(host='0.0.0.0', debug=True)
from flask_restful import Resource, current_app
import requests
import traceback
class ClearCache(Resource):
def get(self):
"""
Tell drupal to clear the import-process-cache
---
tags:
- clear drupal cache
responses:
200:
description: Success, the call to drupal could be executed
500:
description: Failure tha call to drupal could neo be executed
"""
uri = current_app.config['drupal-api-url'] + current_app.config['CLEAR_CACHE_URL']
headers = {'X-API-Key': current_app.config['drupal-api-key']}
try:
response = requests.get(uri, headers=headers)
except Exception as ex:
msg = 'Exception while calling ' + uri + ': ' + str(ex) + '\n' + \
traceback.format_exc()
current_app.logger.error(msg)
return {
'response': response.content.decode("utf-8"),
}, 500
if response.status_code != 200:
current_app.logger.debug('there was an unexpected behaviour calling ' + uri)
current_app.logger.debug('statuscode: ' + response.status_code + ' content: ' +
response.content.decode('utf-8'))
return {
'content': response.content.decode("utf-8"),
}, response.status_code
else:
current_app.logger.debug('successfully called ' + uri)
return {
'content': response.content.decode("utf-8"),
}, 400
Supports Markdown
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