mirror of
https://github.com/titanscouting/tra-superscript.git
synced 2024-12-30 19:39:09 +00:00
Merge pull request #18 from titanscouting/daemon-fix
Fix messaging in daemon
Former-commit-id: 6a4d13a33f
This commit is contained in:
commit
49ee02d6fa
@ -193,7 +193,7 @@ def push_metric(client, competition, metric):
|
||||
def push_pit(client, competition, pit):
|
||||
|
||||
for variable in pit:
|
||||
|
||||
|
||||
push_team_pit_data(client, competition, variable, pit[variable])
|
||||
|
||||
def check_new_database_matches(client, competition):
|
||||
|
@ -151,18 +151,16 @@ __all__ = [
|
||||
|
||||
# imports:
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import math
|
||||
from multiprocessing import Pool, freeze_support
|
||||
import os
|
||||
import pymongo
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
import warnings
|
||||
import websockets
|
||||
import zmq
|
||||
|
||||
from interface import splash, log, ERR, INF, stdout, stderr
|
||||
from data import get_previous_time, pull_new_tba_matches, set_current_time, load_match, push_match, load_pit, push_pit, get_database_config, set_database_config, check_new_database_matches
|
||||
@ -541,43 +539,26 @@ def start(pid_path, verbose = False, profile = False, debug = False):
|
||||
sys.exit(exit_code)
|
||||
|
||||
else:
|
||||
|
||||
|
||||
f = open('errorlog.log', 'w+')
|
||||
with daemon.DaemonContext(
|
||||
working_directory=os.getcwd(),
|
||||
pidfile=pidfile.TimeoutPIDLockFile(pid_path),
|
||||
stderr=f
|
||||
working_directory = os.getcwd(),
|
||||
pidfile = pidfile.TimeoutPIDLockFile(pid_path),
|
||||
stderr = f
|
||||
):
|
||||
|
||||
async def handler(client, path):
|
||||
clients.append(client)
|
||||
while True:
|
||||
try:
|
||||
pong_waiter = await client.ping()
|
||||
await pong_waiter
|
||||
time.sleep(3)
|
||||
except Exception as e:
|
||||
clients.remove(client)
|
||||
break
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.PUB)
|
||||
socket.bind("tcp://*:5678")
|
||||
|
||||
socket.send(b'status')
|
||||
|
||||
async def send_one(client, data):
|
||||
await client.send(data)
|
||||
|
||||
def send(target, level, message, code = 0):
|
||||
message_clients = clients.copy()
|
||||
for client in message_clients:
|
||||
try:
|
||||
asyncio.run(send_one(client, message))
|
||||
except:
|
||||
pass
|
||||
|
||||
clients = []
|
||||
start_server = websockets.serve(handler, "0.0.0.0", 5678)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
threading.Thread(target = asyncio.get_event_loop().run_forever).start()
|
||||
socket.send(bytes("status: " + message, 'utf-8'))
|
||||
|
||||
exit_code = main(send)
|
||||
socket.close()
|
||||
f.close()
|
||||
sys.exit(exit_code)
|
||||
|
||||
def stop(pid_path):
|
||||
|
@ -10,8 +10,6 @@ a = Analysis(['superscript.py'],
|
||||
"dnspython",
|
||||
"sklearn.utils._weight_vector",
|
||||
"requests",
|
||||
"websockets.legacy",
|
||||
"websockets.legacy.server",
|
||||
],
|
||||
hookspath=[],
|
||||
runtime_hooks=[],
|
||||
|
@ -15,5 +15,5 @@ pandas
|
||||
|
||||
kivy==2.0.0rc2
|
||||
|
||||
websockets
|
||||
pyzmq
|
||||
python-daemon
|
14
test/client.py
Normal file
14
test/client.py
Normal file
@ -0,0 +1,14 @@
|
||||
import signal
|
||||
import zmq
|
||||
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
context = zmq.Context()
|
||||
|
||||
socket = context.socket(zmq.SUB)
|
||||
socket.connect('tcp://localhost:5678')
|
||||
socket.setsockopt(zmq.SUBSCRIBE, b'status')
|
||||
|
||||
while True:
|
||||
message = socket.recv_multipart()
|
||||
print(f'Received: {message}')
|
Loading…
Reference in New Issue
Block a user