diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/app.py b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/app.py index f6f1ad1e42ba445bce3b9979d9f2f9da4b965dc3..0a5434889cda682a7848c8a29e24fe662c6ca62d 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/app.py +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/api_invoker_management/app.py @@ -10,6 +10,8 @@ from logging.handlers import RotatingFileHandler import os from fluent import sender from flask_executor import Executor +from flask_apscheduler import APScheduler +from datetime import datetime from opentelemetry.instrumentation.flask import FlaskInstrumentor from opentelemetry import trace from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator @@ -137,16 +139,11 @@ if monitoring_value == "true": executor = Executor(app.app) subscriber = Subscriber() - -first = True - -@app.app.before_request -def create_listener_message(): - global first - if first: - executor.submit(subscriber.listen) - first = False - -# @app.app.before_first_request -# def create_listener_message(): -# executor.submit(subscriber.listen) \ No newline at end of file +scheduler = APScheduler() +scheduler.init_app(app.app) +scheduler.start() + +@scheduler.task('date', id='listener', next_run_time=datetime.now()) +def up_listener(): + with scheduler.app.app_context(): + executor.submit(subscriber.listen()) diff --git a/services/TS29222_CAPIF_API_Invoker_Management_API/requirements.txt b/services/TS29222_CAPIF_API_Invoker_Management_API/requirements.txt index 35990d041772dab3dc0c2968aebfed0ebf583977..34d990eecd2d85c5bd472041a065c18d4246ce80 100644 --- a/services/TS29222_CAPIF_API_Invoker_Management_API/requirements.txt +++ b/services/TS29222_CAPIF_API_Invoker_Management_API/requirements.txt @@ -19,6 +19,7 @@ fluent-logger == 0.10.0 opentelemetry-api == 1.19.0 opentelemetry-sdk == 1.19.0 flask_executor == 1.0.0 +Flask-APScheduler == 1.13.1 werkzeug == 3.0.4 gunicorn == 22.0.0 packaging == 24.0 \ No newline at end of file diff --git a/services/TS29222_CAPIF_Events_API/capif_events/app.py b/services/TS29222_CAPIF_Events_API/capif_events/app.py index a4eb7477c05bf2327a43a523732ecf665d7f511f..d21ee573a3cbbf0f63948e8686652ca56e32d3e6 100644 --- a/services/TS29222_CAPIF_Events_API/capif_events/app.py +++ b/services/TS29222_CAPIF_Events_API/capif_events/app.py @@ -17,6 +17,7 @@ from multiprocessing import Process from threading import Thread from flask_executor import Executor from flask_apscheduler import APScheduler +from datetime import datetime from logging.handlers import RotatingFileHandler from config import Config import os @@ -144,18 +145,11 @@ if monitoring_value == "true": config = Config() executor = Executor(app.app) subscriber = Subscriber() -# scheduler = APScheduler() -# scheduler.init_app(app.app) - -# @app.app.before_first_request -# def create_listener_message(): -# executor.submit(subscriber.listen) - -first = True - -@app.app.before_request -def create_listener_message(): - global first - if first: - executor.submit(subscriber.listen) - first = False +scheduler = APScheduler() +scheduler.init_app(app.app) +scheduler.start() + +@scheduler.task('date', id='listener', next_run_time=datetime.now()) +def up_listener(): + with scheduler.app.app_context(): + executor.submit(subscriber.listen()) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/app.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/app.py index bb155171b5f243abab9ae0d29b078da55fcd88f6..7504d0b7020909a67e013ea4d18c71fd2194a978 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/app.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/app.py @@ -15,6 +15,8 @@ import os from fluent import sender from flask_executor import Executor from opentelemetry.instrumentation.flask import FlaskInstrumentor +from flask_apscheduler import APScheduler +from datetime import datetime from opentelemetry import trace from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator @@ -134,12 +136,12 @@ if monitoring_value == "true": executor = Executor(app.app) subscriber = Subscriber() +scheduler = APScheduler() +scheduler.init_app(app.app) +scheduler.start() -first = True - -@app.app.before_request +@scheduler.task('date', id='listener', next_run_time=datetime.now()) def up_listener(): - global first - if first: - executor.submit(subscriber.listen) - first = False + with scheduler.app.app_context(): + executor.submit(subscriber.listen()) + diff --git a/services/TS29222_CAPIF_Publish_Service_API/requirements.txt b/services/TS29222_CAPIF_Publish_Service_API/requirements.txt index c8f56292ab28239f55de950bb27d1fe525907951..0496b8e4b3591b45b7f93c1b60ba8c10807f6e5e 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/requirements.txt +++ b/services/TS29222_CAPIF_Publish_Service_API/requirements.txt @@ -18,6 +18,7 @@ fluent-logger == 0.10.0 opentelemetry-api == 1.17.0 opentelemetry-sdk == 1.17.0 flask_executor == 1.0.0 +Flask-APScheduler == 1.13.1 werkzeug == 3.0.4 gunicorn == 22.0.0 packaging == 24.0 diff --git a/services/TS29222_CAPIF_Security_API/capif_security/app.py b/services/TS29222_CAPIF_Security_API/capif_security/app.py index 07dc9ad2a9352b3c02aa752266736c4eb144ab28..08ec64190b75e8327f53a86f3663ea8d6a655ce1 100644 --- a/services/TS29222_CAPIF_Security_API/capif_security/app.py +++ b/services/TS29222_CAPIF_Security_API/capif_security/app.py @@ -6,6 +6,8 @@ import encoder from flask_jwt_extended import JWTManager from config import Config from core.consumer_messager import Subscriber +from flask_apscheduler import APScheduler +from datetime import datetime from logging.handlers import RotatingFileHandler import os from fluent import sender @@ -134,12 +136,11 @@ if monitoring_value == "true": configure_monitoring(app.app, config.get_config()) executor = Executor(app.app) +scheduler = APScheduler() +scheduler.init_app(app.app) +scheduler.start() -first = True - -@app.app.before_request +@scheduler.task('date', id='listener', next_run_time=datetime.now()) def up_listener(): - global first - if first: - executor.submit(subscriber.listen) - first = False + with scheduler.app.app_context(): + executor.submit(subscriber.listen()) diff --git a/services/TS29222_CAPIF_Security_API/requirements.txt b/services/TS29222_CAPIF_Security_API/requirements.txt index 35990d041772dab3dc0c2968aebfed0ebf583977..b3fd4f79e3b770f780fc9feba3d110657f189e87 100644 --- a/services/TS29222_CAPIF_Security_API/requirements.txt +++ b/services/TS29222_CAPIF_Security_API/requirements.txt @@ -18,6 +18,7 @@ fluent == 0.10.0 fluent-logger == 0.10.0 opentelemetry-api == 1.19.0 opentelemetry-sdk == 1.19.0 +Flask-APScheduler == 1.13.1 flask_executor == 1.0.0 werkzeug == 3.0.4 gunicorn == 22.0.0