oarepo-runtime 1.5.64__py3-none-any.whl → 1.5.65__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
1
+ import json, random
2
+ from flask import Response, Blueprint
3
+ from flask import current_app as flask_current_app
4
+ from invenio_db import db # sql alchemy session
5
+ from invenio_cache import current_cache # redis
6
+ import redis
7
+ from invenio_search import current_search_client # opensearch
8
+ from celery import current_app as celery_current_app, shared_task
9
+
10
+
11
+ def check_db_connection():
12
+ if not has_database_connection():
13
+ return "DB connection failed"
14
+ else:
15
+ return "ok"
16
+
17
+ def has_database_connection():
18
+ try:
19
+ db.session.begin()
20
+ db.session.execute("select * from alembic_version").scalar()
21
+ return True
22
+ except:
23
+ return False
24
+ finally:
25
+ db.session.rollback()
26
+
27
+ def check_cache_connection():
28
+ try:
29
+ rand = random.randint(1, 1000)
30
+ if current_cache.set('mykey', str(rand)):
31
+ val = current_cache.get('mykey')
32
+ if val == str(rand):
33
+ return "ok"
34
+ else:
35
+ return "Cache returned unexpected value."
36
+ else:
37
+ return "Failed to set cache key."
38
+ except redis.exceptions.ConnectionError as e:
39
+ if isinstance(e.__cause__, ConnectionRefusedError):
40
+ return "Cache connection error"
41
+ return "Cache exception"
42
+ except Exception as other:
43
+ return str(other)
44
+
45
+
46
+
47
+ # https://github.com/celery/celery/issues/4283
48
+ def check_message_queue():
49
+ from kombu.exceptions import OperationalError
50
+ try:
51
+ #celery_current_app.autodiscover_tasks(['oarepo_runtime.info'])
52
+ ping_task = celery_current_app.send_task('ping')
53
+ if ping_task.get(timeout=2) == 'pong':
54
+ return "ok"
55
+ except OperationalError as e:
56
+ if isinstance(e.__cause__, ConnectionRefusedError):
57
+ return "RabbitMQ connection refused"
58
+ return "Other RabbitMQ-related error"
59
+ except Exception as other:
60
+ return str(other)
61
+
62
+
63
+ def check_opensearch():
64
+ try:
65
+ is_available = current_search_client.ping()
66
+ if is_available:
67
+ return "ok"
68
+ else:
69
+ return "OpenSearch is not available"
70
+ except Exception as e:
71
+ return str(e)
72
+
73
+
74
+ blueprint = Blueprint("repository-check", __name__, url_prefix="/.well-known")
75
+
76
+ @blueprint.route("/check")
77
+ def check_connections() -> Response:
78
+ """
79
+ Function to check all necessary connections (database, redis, rabbitmq, opensearch)
80
+ Return Response 200 if everything is OK or Response 500 with json and all failed tests
81
+ """
82
+ check_list = {}
83
+ with flask_current_app.app_context():
84
+ check_list['db'] = check_db_connection()
85
+ check_list['cache'] = check_cache_connection()
86
+ check_list['mq'] = check_message_queue()
87
+ check_list['opensearch'] = check_opensearch()
88
+
89
+ failed_checks = {key: value for key, value in check_list.items() if value != 'ok'}
90
+
91
+ if failed_checks:
92
+ return Response(json.dumps(failed_checks), status=500, content_type='application/json')
93
+
94
+ return Response(json.dumps(check_list), status=200, content_type='application/json') # good
95
+
96
+
@@ -0,0 +1,6 @@
1
+ from celery import shared_task
2
+
3
+ # TODO priority if something big is in queue already
4
+ @shared_task(name='ping')
5
+ def ping():
6
+ return 'pong'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.64
3
+ Version: 1.5.65
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -3,6 +3,7 @@ oarepo_runtime/ext.py,sha256=zatf-tujtuP1Flo34p_5GJ38yKxzkAz0ENBjljapPlA,2373
3
3
  oarepo_runtime/ext_config.py,sha256=NiXqgag3QJABf06r5NiDYjd9AvoYoRY9UWiplo8Vcg4,2056
4
4
  oarepo_runtime/profile.py,sha256=QzrQoZncjoN74ZZnpkEKakNk08KCzBU7m6y42RN8AMY,1637
5
5
  oarepo_runtime/proxies.py,sha256=NN_WNj1xuKc-OveoZmzvTFlUonNjSmLIGsv_JUcHGls,285
6
+ oarepo_runtime/tasks.py,sha256=AciXN1fUq6tzfzNSICh1S6XoHGWiuH76bUqXyzTsOPU,140
6
7
  oarepo_runtime/uow.py,sha256=iyF3R2oCPSVUu38GXoxZallgRD-619q1fWTb8sSaeyQ,4412
7
8
  oarepo_runtime/cli/__init__.py,sha256=daAODgUAB9Nb0O0Kg8vSgJIPKJm92EHMTRuoKwxBCug,373
8
9
  oarepo_runtime/cli/assets.py,sha256=Yrg9O2dXmrOGH87_3SNxmgrgyt2w4ZzkvQQJVTmLZjk,3634
@@ -41,6 +42,7 @@ oarepo_runtime/datastreams/writers/validation_errors.py,sha256=wOCXdniR6so_4Expd
41
42
  oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8Hfoye6yaR0gKI,1482
42
43
  oarepo_runtime/i18n/__init__.py,sha256=h0knW_HwiyIt5TBHfdGqN7_BBYfpz1Fw6zhVy0C28fM,111
43
44
  oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
+ oarepo_runtime/info/check.py,sha256=WWAqMIBmc7veQKflRBe97_PoDsvJ1DrDrJuTDNeGDaI,3076
44
46
  oarepo_runtime/info/views.py,sha256=UkLGzf6Vo8GLutfzJW3IAyq9sdPexICUFAvz903autY,11829
45
47
  oarepo_runtime/records/__init__.py,sha256=3vzRsAPxl4d5QOnGyls-vUg4E6PunmR4ACObtacMAIQ,1038
46
48
  oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
@@ -119,9 +121,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
119
121
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
120
122
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
121
123
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
122
- oarepo_runtime-1.5.64.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
- oarepo_runtime-1.5.64.dist-info/METADATA,sha256=PUOOR2X2Q4nhO6-QdV8-O4b0R7SvNP06YXPP9aMfZdY,4720
124
- oarepo_runtime-1.5.64.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
- oarepo_runtime-1.5.64.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
- oarepo_runtime-1.5.64.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
- oarepo_runtime-1.5.64.dist-info/RECORD,,
124
+ oarepo_runtime-1.5.65.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
125
+ oarepo_runtime-1.5.65.dist-info/METADATA,sha256=ZgBG9WKIQEODgFiYua5ZpiwmylRyGKmT2tIXq7mQDGo,4720
126
+ oarepo_runtime-1.5.65.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
127
+ oarepo_runtime-1.5.65.dist-info/entry_points.txt,sha256=0cschM0RHc6UJ1uudhu4EP0hrVStPGpgMO-XEDGRtY4,430
128
+ oarepo_runtime-1.5.65.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
129
+ oarepo_runtime-1.5.65.dist-info/RECORD,,
@@ -5,7 +5,9 @@ oarepo_runtime = oarepo_runtime.ext:OARepoRuntime
5
5
  oarepo_runtime = oarepo_runtime.ext:OARepoRuntime
6
6
 
7
7
  [invenio_base.blueprints]
8
+ oarepo_runtime_check = oarepo_runtime.info.check:blueprint
8
9
  oarepo_runtime_info = oarepo_runtime.info.views:create_wellknown_blueprint
9
10
 
10
11
  [invenio_celery.tasks]
12
+ oarepo_runtime_check = oarepo_runtime.tasks
11
13
  oarepo_runtime_datastreams = oarepo_runtime.datastreams