Commit c728ae75 authored by Jorrit Schaap's avatar Jorrit Schaap

TMSS-180: (and TMSS-60) implemented a TMSSSubTaskBusListener in a TMSSClient...

TMSS-180: (and TMSS-60) implemented a TMSSSubTaskBusListener in a TMSSClient package, and used it to send/receice TMSS Subtask status changes messages


(cherry picked from commit 7d07a86f)
parent 31622e1b
# - Create for each LOFAR package a variable containing the absolute path to
# its source directory.
#
# Generated by gen_LofarPackageList_cmake.sh at Fr 28. Feb 20:47:32 CET 2020
# Generated by gen_LofarPackageList_cmake.sh at ma 4 mei 2020 12:07:08 CEST
#
# ---- DO NOT EDIT ----
#
......@@ -142,7 +142,6 @@ if(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED)
set(OTDB_Comps_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/Deployment/data/OTDB)
set(StaticMetaData_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/Deployment/data/StaticMetaData)
set(WinCCPublisher_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/WinCCPublisher)
set(WinCCREST_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/WinCCREST)
set(WinCCDBBridge_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/WinCCDBBridge)
set(TaskManagement_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/Services/TaskManagement)
set(TBB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/MAC/TBB)
......@@ -207,6 +206,7 @@ if(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED)
set(RAScripts_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/ResourceAssignment/RAScripts)
set(TaskPrescheduler_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/ResourceAssignment/TaskPrescheduler)
set(RACommon_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/ResourceAssignment/Common)
set(TMSSClient_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TMSS/client)
set(TriggerEmailServiceCommon_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TriggerEmailService/Common)
set(TriggerEmailServiceServer_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TriggerEmailService/Server)
set(CCU_MAC_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SubSystems/CCU_MAC)
......
......@@ -8,3 +8,5 @@ add_subdirectory(test)
add_subdirectory(frontend)
lofar_add_docker_files(docker-compose-tmss.yml)
lofar_add_package(TMSSClient client)
lofar_package(TMSSClient 0.1 DEPENDS PyCommon pyparameterset PyMessaging)
lofar_find_package(PythonInterp 3.4 REQUIRED)
include(PythonInstall)
set(_py_files
tmssbuslistener.py
)
python_install(${_py_files}
DESTINATION lofar/sas/tmss/client)
This diff is collapsed.
......@@ -2,6 +2,9 @@
This file contains the database models
"""
import logging
logger = logging.getLogger(__name__)
from django.db.models import ForeignKey, CharField, DateTimeField, BooleanField, IntegerField, BigIntegerField, \
ManyToManyField, CASCADE, SET_NULL, PROTECT
from django.contrib.postgres.fields import ArrayField, JSONField
......@@ -12,6 +15,9 @@ from rest_framework.serializers import HyperlinkedRelatedField
from django.dispatch import receiver
from lofar.sas.tmss.tmss.tmssapp.validation import validate_json_against_schema
from lofar.messaging.messagebus import ToBus
from lofar.messaging.messages import EventMessage
from lofar.sas.tmss.client.tmssbuslistener import DEFAULT_TMSS_SUBTASK_NOTIFICATION_PREFIX
#
# I/O
......@@ -158,6 +164,13 @@ class Subtask(BasicCommon):
# keep original state for logging
self.__original_state = self.state
@staticmethod
def _send_state_change_event_message(subtask_id:int, old_state: str, new_state: str):
with ToBus() as tobus: #TODO: do we want to connect to the bus for each new message, or have some global tobus?
msg = EventMessage(subject="%s.%s" % (DEFAULT_TMSS_SUBTASK_NOTIFICATION_PREFIX, new_state.capitalize()),
content={'subtask_id': subtask_id, 'old_state': old_state, 'new_state': new_state})
tobus.send(msg)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
creating = self._state.adding # True on create, False on update
......@@ -167,7 +180,7 @@ class Subtask(BasicCommon):
super().save(force_insert, force_update, using, update_fields)
# log if either state update or new entry:
if self.state != self.__original_state or creating is True:
if self.state != self.__original_state or creating == True:
if self.created_or_updated_by_user is None:
identifier = None
else:
......@@ -176,6 +189,10 @@ class Subtask(BasicCommon):
user=self.created_or_updated_by_user, user_identifier=identifier)
log_entry.save()
try:
self._send_state_change_event_message(self.id, log_entry.old_state.value, log_entry.new_state.value)
except Exception as e:
logger.error("Could not send state change to messagebug: %s", e)
class SubtaskStateLog(BasicCommon):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment