Skip to content
Snippets Groups Projects
Commit a1606db1 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-419: moved Fabio's implementation from the messagehandler.py where it...

TMSS-419: moved Fabio's implementation from the messagehandler.py where it started running the listener upon import to a nicely loosly coupled standalone service: tmss_workflow_service. Added this service also to the TMSSTestEnviroment where it will run when enable_workflow and start_workflow_service are true.
parent 19194ac6
No related branches found
No related tags found
1 merge request!268Resolve TMSS-419
lofar_package(TMSSWorkflowService 0.1 DEPENDS TMSSClient PyCommon pyparameterset PyMessaging)
lofar_find_package(PythonInterp 3.4 REQUIRED)
add_subdirectory(lib)
add_subdirectory(bin)
lofar_add_bin_scripts(tmss_workflow_service)
# supervisord config files
lofar_add_sysconf_files(tmss_workflow_service.ini DESTINATION supervisord.d)
#!/usr/bin/python3
# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy)
# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
if __name__ == '__main__':
from lofar.sas.tmss.services.workflow_service import main
main()
[program:tmss_workflow_service]
command=/bin/bash -c 'source $LOFARROOT/lofarinit.sh;exec tmss_workflow_service'
user=lofarsys
stopsignal=INT ; KeyboardInterrupt
stopasgroup=true ; bash does not propagate signals
stdout_logfile=%(program_name)s.log
redirect_stderr=true
stderr_logfile=NONE
stdout_logfile_maxbytes=0
lofar_find_package(PythonInterp 3.4 REQUIRED)
include(PythonInstall)
set(_py_files
workflow_service.py
)
python_install(${_py_files}
DESTINATION lofar/sas/tmss/services)
#!/usr/bin/env python3
# subtask_scheduling.py
#
# Copyright (C) 2015
# ASTRON (Netherlands Institute for Radio Astronomy)
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This file is part of the LOFAR software suite.
# The LOFAR software suite is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# The LOFAR software suite is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
#
import os
import logging
logger = logging.getLogger(__name__)
from lofar.sas.tmss.client.tmssbuslistener import *
class SchedulingUnitEventMessageHandler(TMSSEventMessageHandler):
def onSchedulingUnitBlueprintStatusChanged(self, id: int, status: str):
try:
# import here and not at top of module because we need the django.setup() to be run first, either from this module's main, or from the TMSSTestEnvironment
from lofar.sas.tmss.tmss.workflowapp.signals import scheduling_unit_blueprint_signal
from lofar.sas.tmss.tmss.tmssapp.models import SchedulingUnitBlueprint
logger.info("SchedulingUnitBlueprint id=%s status changed to '%s', signalling workflow...", id, status)
scheduling_unit_blueprint = SchedulingUnitBlueprint.objects.get(pk=id)
scheduling_unit_blueprint_signal.send(sender=self.__class__, instance=scheduling_unit_blueprint, status=status)
except Exception as e:
logger.error(e)
def create_workflow_service(exchange: str=DEFAULT_BUSNAME, broker: str=DEFAULT_BROKER):
return TMSSBusListener(handler_type=SchedulingUnitEventMessageHandler,
handler_kwargs={},
exchange=exchange, broker=broker)
def main():
# make sure we run in UTC timezone
os.environ['TZ'] = 'UTC'
from optparse import OptionParser, OptionGroup
from lofar.common import dbcredentials
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
# Check the invocation arguments
parser = OptionParser('%prog [options]',
description='run the tmss_workflow_service which forwards TMSS events to the workflow engine.')
group = OptionGroup(parser, 'Messaging options')
group.add_option('-b', '--broker', dest='broker', type='string', default=DEFAULT_BROKER,
help='Address of the message broker, default: %default')
group.add_option('-e', "--exchange", dest="exchange", type="string", default=DEFAULT_BUSNAME,
help="Bus or queue where the TMSS messages are published. [default: %default]")
parser.add_option_group(group)
parser.add_option_group(dbcredentials.options_group(parser))
parser.set_defaults(dbcredentials=os.environ.get('TMSS_DBCREDENTIALS', 'TMSS'))
(options, args) = parser.parse_args()
dbcreds = dbcredentials.parse_options(options)
logger.info("Using TMSS dbcreds: %s" % dbcreds.stringWithHiddenPassword())
# setup django
os.environ["TMSS_DBCREDENTIALS"] = options.dbcredentials
os.environ["DJANGO_SETTINGS_MODULE"] = "lofar.sas.tmss.tmss.settings"
os.environ['TMSS_ENABLE_VIEWFLOW'] = 'True'
import django
django.setup()
with create_workflow_service(options.exchange, options.broker):
waitForInterrupt()
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment