-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGbcOcrImagePdf2ReadableCacheCleanerResource.py
More file actions
55 lines (46 loc) · 1.82 KB
/
Copy pathGbcOcrImagePdf2ReadableCacheCleanerResource.py
File metadata and controls
55 lines (46 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
from flask import jsonify
from flask_restx import Resource, fields, reqparse
from commonsLib import loggerElk
class GbcOcrImagePdf2ReadableCacheCleanerResource(Resource):
from api import api
ELK_ENABLED = os.environ["ELK_ENABLED"]
if isinstance(ELK_ENABLED, str):
ELK_ENABLED = True if ELK_ENABLED == "True" else False
print(f"ELK_ENABLED: {ELK_ENABLED}")
logger = loggerElk(__name__)
DEFAULT_TXT_LEN_FOR_SKIP = 100
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
from api import app
from services import CacheCleanerService
self.service = CacheCleanerService(app=app)
request_fields = {
'key': fields.String(required=True, description='Key of the file'),
'bucket': fields.String(required=True, description='The bucket of the file'),
}
@api.doc(
description='Remove cached files for Pdf2Readable',
responses={
200: 'OK',
400: 'Invalid Argument',
500: 'Internal Error'})
@api.expect(request_fields)
def post(self):
key = ''
try:
self.logger.Information('GbcOcrImagePdf2ReadableCacheCleanerResource::POST - init')
parser = reqparse.RequestParser()
parser.add_argument('key', type=str, location='json')
parser.add_argument('bucket', type=str, location='json')
args = parser.parse_args()
return jsonify(self.service.post(args))
except Exception as e:
self.logger.Error(f'ERROR - GbcOcrImagePdf2ReadableCacheCleanerResource::POST- {key} ' + str(e.args),
sys.exc_info())
return jsonify({
'status': 'False',
'statusCode': 500,
'message': str(e)
})