diff --git a/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py b/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py index 5e197efa6af95fc9446a20722ad130442b55c9dc..cdc9bed5b68036ee2a12395766d7a70b8b0f7f90 100644 --- a/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py +++ b/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py @@ -207,43 +207,43 @@ class TMSSPGListener(PostgresListener): subtask = Subtask.objects.get(id=subtask_id) # check if task is new or changed... If so, send event. - for task_blueprint in subtask.task_blueprints.all(): - task_id = task_blueprint.id - task_cached_properties = {'status': task_blueprint.status, - 'start_time': task_blueprint.start_time, - 'stop_time': task_blueprint.stop_time } - - if task_id not in self._task_cache or self._task_cache[task_id][1] != task_cached_properties: - # send generic updated event - self.onTaskBlueprintUpdated( {'id': task_id}) - - # only send status updated event when the status changed - if task_cached_properties['status'] != self._task_cache.get(task_id, (None, {}))[1].get('status'): - self._sendNotification(TMSS_TASKBLUEPRINT_STATUS_EVENT_PREFIX+'.'+task_cached_properties['status'].capitalize(), - {'id': task_id, 'status': task_cached_properties['status']}) - - # update cache for this task - self._task_cache[task_id] = (datetime.utcnow(), task_cached_properties) - - - # check if scheduling_unit status is new or changed... If so, send event. - scheduling_unit = task_blueprint.scheduling_unit_blueprint - scheduling_unit_id = scheduling_unit.id - scheduling_unit_cached_properties = {'status': scheduling_unit.status, - 'start_time': scheduling_unit.start_time, - 'stop_time': scheduling_unit.stop_time } - - if scheduling_unit_id not in self._scheduling_unit_cache or self._scheduling_unit_cache[scheduling_unit_id][1] != scheduling_unit_cached_properties: - # send generic updated event - self.onSchedulingUnitBlueprintUpdated( {'id': scheduling_unit_id}) - - # only send status updated event when the status changed - if scheduling_unit_cached_properties['status'] != self._scheduling_unit_cache.get(scheduling_unit_id, (None, {}))[1].get('status'): - self._sendNotification(TMSS_SCHEDULINGUNITBLUEPRINT_STATUS_EVENT_PREFIX+'.'+scheduling_unit_cached_properties['status'].capitalize(), - {'id': scheduling_unit_id, 'status': scheduling_unit_cached_properties['status']}) - - # update cache for this task - self._scheduling_unit_cache[scheduling_unit_id] = (datetime.utcnow(), scheduling_unit_cached_properties) + task_blueprint = subtask.task_blueprint + task_id = subtask.task_blueprint.id + task_cached_properties = {'status': task_blueprint.status, + 'start_time': task_blueprint.start_time, + 'stop_time': task_blueprint.stop_time } + + if task_id not in self._task_cache or self._task_cache[task_id][1] != task_cached_properties: + # send generic updated event + self.onTaskBlueprintUpdated( {'id': task_id}) + + # only send status updated event when the status changed + if task_cached_properties['status'] != self._task_cache.get(task_id, (None, {}))[1].get('status'): + self._sendNotification(TMSS_TASKBLUEPRINT_STATUS_EVENT_PREFIX+'.'+task_cached_properties['status'].capitalize(), + {'id': task_id, 'status': task_cached_properties['status']}) + + # update cache for this task + self._task_cache[task_id] = (datetime.utcnow(), task_cached_properties) + + + # check if scheduling_unit status is new or changed... If so, send event. + scheduling_unit = task_blueprint.scheduling_unit_blueprint + scheduling_unit_id = scheduling_unit.id + scheduling_unit_cached_properties = {'status': scheduling_unit.status, + 'start_time': scheduling_unit.start_time, + 'stop_time': scheduling_unit.stop_time } + + if scheduling_unit_id not in self._scheduling_unit_cache or self._scheduling_unit_cache[scheduling_unit_id][1] != scheduling_unit_cached_properties: + # send generic updated event + self.onSchedulingUnitBlueprintUpdated( {'id': scheduling_unit_id}) + + # only send status updated event when the status changed + if scheduling_unit_cached_properties['status'] != self._scheduling_unit_cache.get(scheduling_unit_id, (None, {}))[1].get('status'): + self._sendNotification(TMSS_SCHEDULINGUNITBLUEPRINT_STATUS_EVENT_PREFIX+'.'+scheduling_unit_cached_properties['status'].capitalize(), + {'id': scheduling_unit_id, 'status': scheduling_unit_cached_properties['status']}) + + # update cache for this task + self._scheduling_unit_cache[scheduling_unit_id] = (datetime.utcnow(), scheduling_unit_cached_properties) except Subtask.DoesNotExist: pass