diff --git a/src/monitoring/service/AlarmManager.py b/src/monitoring/service/AlarmManager.py index 27b169b164f0e2ca6534caf72bb0cf1ad71df8dd..d80d815fe50395e360d0fc9e932168fa6e1a0174 100644 --- a/src/monitoring/service/AlarmManager.py +++ b/src/monitoring/service/AlarmManager.py @@ -24,11 +24,12 @@ class AlarmManager(): start_date = datetime.utcfromtimestamp(start_timestamp).isoformat() end_date = datetime.utcfromtimestamp(end_timestamp).isoformat() - self.scheduler.add_job(self.metrics_db.get_alarm_data, + job = self.scheduler.add_job(self.metrics_db.get_alarm_data, args=(alarm_queue,kpi_id, kpiMinValue, kpiMaxValue, inRange, includeMinValue, includeMaxValue, subscription_frequency_ms), trigger='interval', seconds=(subscription_frequency_ms/1000), start_date=start_date, end_date=end_date,timezone=pytz.utc, id=str(alarm_id)) LOGGER.debug(f"Alarm job {alarm_id} succesfully created") + job.remove() def delete_alarm(self, alarm_id): try: diff --git a/src/monitoring/service/SubscriptionManager.py b/src/monitoring/service/SubscriptionManager.py index f76cf8c394b26c552757acec3a6185af8cd69114..6ff922c52dea10b0301ff5f765b045e125e42c05 100644 --- a/src/monitoring/service/SubscriptionManager.py +++ b/src/monitoring/service/SubscriptionManager.py @@ -42,10 +42,11 @@ class SubscriptionManager(): if end_timestamp: end_date = datetime.utcfromtimestamp(end_timestamp).isoformat() - self.scheduler.add_job(self.metrics_db.get_subscription_data, args=(subs_queue,kpi_id, sampling_interval_s), + job = self.scheduler.add_job(self.metrics_db.get_subscription_data, args=(subs_queue,kpi_id, sampling_interval_s), trigger='interval', seconds=sampling_interval_s, start_date=start_date, end_date=end_date, timezone=pytz.utc, id=str(subscription_id)) LOGGER.debug(f"Subscrition job {subscription_id} succesfully created") + job.remove() def delete_subscription(self, subscription_id): self.scheduler.remove_job(subscription_id) diff --git a/src/monitoring/tests/test_unitary.py b/src/monitoring/tests/test_unitary.py index 82399889977dbb8cf170a7e756e08cecb67fbc1d..55ac9a18b2cd907781c9bbe12fa15ba622e95258 100644 --- a/src/monitoring/tests/test_unitary.py +++ b/src/monitoring/tests/test_unitary.py @@ -22,6 +22,7 @@ from typing import Tuple from apscheduler.executors.pool import ProcessPoolExecutor from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.schedulers.base import STATE_STOPPED from grpc._channel import _MultiThreadedRendezvous from common.Constants import ServiceNameEnum @@ -299,6 +300,8 @@ def test_set_kpi_subscription(monitoring_client,metrics_db,subs_scheduler): # py for item in response: LOGGER.debug(item) assert isinstance(item, SubsResponse) + if (subs_scheduler.state != STATE_STOPPED): + subs_scheduler.shutdown() # Test case that makes use of client fixture to test server's GetSubsDescriptor method def test_get_subs_descriptor(monitoring_client): @@ -364,6 +367,9 @@ def test_get_alarm_response_stream(monitoring_client,subs_scheduler): LOGGER.debug(item) assert isinstance(item,AlarmResponse) + if(subs_scheduler.state != STATE_STOPPED): + subs_scheduler.shutdown() + # Test case that makes use of client fixture to test server's DeleteAlarm method def test_delete_alarm(monitoring_client): LOGGER.warning('test_delete_alarm') @@ -390,7 +396,6 @@ def test_get_stream_kpi(monitoring_client): # pylint: disable=redefined-outer-na # LOGGER.debug(response) # assert isinstance(response, Kpi) - def test_managementdb_tools_insert_kpi(management_db): # pylint: disable=redefined-outer-name LOGGER.warning('test_managementdb_tools_insert_kpi begin') _create_kpi_request = create_kpi_request()