#!python
# -*- coding: utf-8 -*-
# Copyright (C) Branson Stephens (2015)
#
# This file is part of lvalert-overseer
#
# lvalert-overseer 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.
#
# It 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 LIGO.ORG.  If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from ligo.overseer.overseer_client import send_to_overseer
import logging, time
from twisted.internet import reactor
from multiprocessing import Process, Manager

logger = logging.getLogger('overseer_test_client')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

manager = Manager()

port = 8001
node_name = 'test_superevent'

n = 0
while True:
    time.sleep(0.2)
    mdict = {
        'message': '{n} | {ts}'.format(n=n, ts=datetime.now().isoformat()),
        'node_name' : node_name,
        'action': 'push'
    }
    rdict = manager.dict()
    p = Process(target=send_to_overseer, args=(mdict, rdict, logger, True, port))
    p.start()
    p.join()
    n += 1
