ClearCache.py 1.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
        """

21
        uri = current_app.config['drupal-api-url'] + current_app.config['clear-cache-url']
22
23
24
25
26
27
28
29
30
31
32
33
        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)
Sebastian Schüpbach's avatar
Sebastian Schüpbach committed
34
            current_app.logger.debug('statuscode: ' + str(response.status_code) + ' content: ' +
35
36
37
38
39
40
41
42
                                     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"),
Matthias's avatar
Matthias committed
43
                   }, 200