Newer
Older
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import atexit
import argparse
from flask import Flask, jsonify
from flask import request, send_file
from apscheduler.schedulers.background import BackgroundScheduler
from main import main
from lib.my_logging import logging
from lib.geonetwork_helper import RecordNotFound
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
# read 'n' parse the configuration
with open("config.yaml", 'r') as yamlfile:
cfg = load(yamlfile, Loader=Loader)
cfg['rabbitmq']['host'] = os.environ['RMQ_HOST']
try:
cfg['rabbitmq']['port'] = os.environ['RMQ_PORT']
except KeyError:
cfg['rabbitmq']['port'] = 5672
cfg['rabbitmq']['exchange'] = os.environ['RMQ_EXCHANGE']
logging.getLogger().setLevel(os.environ['LOGLEVEL'])
# def say_hi():
# print("Hi!")
# return
# scheduler = BackgroundScheduler()
# #scheduler.add_job(refresh_cache, 'cron', hour='6', minute='0')
# scheduler.add_job(say_hi, 'interval', seconds=3)
# scheduler.start()
#
# # Shut down the scheduler when exiting the app
# atexit.register(lambda: scheduler.shutdown())
# #from main import refresh_cache
api = Flask(__name__, static_url_path='')
@api.route("/test")
def test():
return jsonify({'test': "ok"})
# @api.before_first_request
# def init_scheduler():
# scheduler = BackgroundScheduler()
# #scheduler.add_job(refresh_cache, 'cron', hour='6', minute='0')
# scheduler.add_job(say_hi, 'interval', seconds=3)
# scheduler.start()
#
# # Shut down the scheduler when exiting the app
# atexit.register(lambda: scheduler.shutdown())
@api.route("/uuid/<uuid>", methods=["GET"])
def _main(uuid):
cfg['metadata_getter']['uuids_to_get'] = [uuid]
try:
main(cfg)
return jsonify({'result': 'ok'}), 200
except RecordNotFound as e:
logging.error(e)
return jsonify({'result': str(e)}), 404
except Exception as e:
logging.error(e)
return jsonify({'result': e}), 400
if __name__ == '__main__':
api.run(host='0.0.0.0', port=8000, debug=True)