mirror of https://github.com/nucypher/nucypher.git
Make moe slightly more conventioanl wrt starting a wsgi app and using cli actions module
parent
51eaad2c91
commit
dba872456c
|
@ -50,3 +50,45 @@ class Moe(Character):
|
|||
new_teacher = self.current_teacher_node(cycle=False)
|
||||
hey_joe.send({"current_teacher": new_teacher.checksum_public_address}, "teachers")
|
||||
return new_nodes
|
||||
|
||||
def start(self, ws_port: int, http_port: int, dry_run: bool = False):
|
||||
|
||||
#
|
||||
# Websocket Service
|
||||
#
|
||||
|
||||
def send_states(subscriber):
|
||||
message = ["states", self.known_nodes.abridged_states_dict()]
|
||||
subscriber.sendMessage(json.dumps(message).encode())
|
||||
|
||||
def send_nodes(subscriber):
|
||||
message = ["nodes", self.known_nodes.abridged_nodes_dict()]
|
||||
subscriber.sendMessage(json.dumps(message).encode())
|
||||
|
||||
websocket_service = hey_joe.WebSocketService("127.0.0.1", ws_port)
|
||||
websocket_service.register_followup("states", send_states)
|
||||
websocket_service.register_followup("nodes", send_nodes)
|
||||
|
||||
#
|
||||
# WSGI Service
|
||||
#
|
||||
|
||||
self.rest_app = Flask("fleet-monitor", root_path=os.path.dirname(__file__))
|
||||
rest_app = self.rest_app
|
||||
|
||||
@rest_app.route("/")
|
||||
def status():
|
||||
template_path = os.path.join('monitor.html')
|
||||
return render_template(template_path)
|
||||
|
||||
#
|
||||
# Server
|
||||
#
|
||||
|
||||
deployer = HendrixDeploy(action="start", options={"wsgi": rest_app, "http_port": http_port})
|
||||
deployer.add_non_tls_websocket_service(websocket_service)
|
||||
|
||||
click.secho(f"Running Moe on 127.0.0.1:{http_port}")
|
||||
|
||||
if not dry_run:
|
||||
deployer.run()
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
import json
|
||||
import os.path
|
||||
|
||||
import click
|
||||
from constant_sorrow import constants
|
||||
from flask import Flask, render_template
|
||||
from hendrix.deploy.base import HendrixDeploy
|
||||
from hendrix.experience import hey_joe
|
||||
|
||||
from nucypher.characters.banners import MOE_BANNER
|
||||
from nucypher.characters.chaotic import Moe
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.cli import actions
|
||||
from nucypher.cli.types import NETWORK_PORT
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
|
||||
|
@ -28,18 +21,11 @@ def moe(teacher_uri, min_stake, network, ws_port, dry_run, http_port, learn_on_l
|
|||
"Moe" NuCypher node monitor CLI.
|
||||
"""
|
||||
|
||||
click.secho(MOE_BANNER)
|
||||
|
||||
#
|
||||
# Teacher
|
||||
#
|
||||
|
||||
teacher_nodes = list()
|
||||
if teacher_uri:
|
||||
teacher_node = Ursula.from_seed_and_stake_info(seed_uri=teacher_uri,
|
||||
federated_only=True,
|
||||
minimum_stake=min_stake)
|
||||
teacher_nodes.append(teacher_node)
|
||||
# Teacher Ursula
|
||||
teacher_uris = [teacher_uri] if teacher_uri else list()
|
||||
teacher_nodes = actions.load_seednodes(teacher_uris=teacher_uris,
|
||||
min_stake=min_stake,
|
||||
federated_only=True) # TODO: hardcoded for now
|
||||
|
||||
# Deserialize network domain name if override passed
|
||||
if network:
|
||||
|
@ -52,46 +38,7 @@ def moe(teacher_uri, min_stake, network, ws_port, dry_run, http_port, learn_on_l
|
|||
domains=domains,
|
||||
network_middleware=RestMiddleware(),
|
||||
known_nodes=teacher_nodes,
|
||||
federated_only=True,
|
||||
)
|
||||
federated_only=True)
|
||||
|
||||
monitor.start_learning_loop(now=learn_on_launch)
|
||||
|
||||
#
|
||||
# Websocket Service
|
||||
#
|
||||
|
||||
def send_states(subscriber):
|
||||
message = ["states", monitor.known_nodes.abridged_states_dict()]
|
||||
subscriber.sendMessage(json.dumps(message).encode())
|
||||
|
||||
def send_nodes(subscriber):
|
||||
message = ["nodes", monitor.known_nodes.abridged_nodes_dict()]
|
||||
subscriber.sendMessage(json.dumps(message).encode())
|
||||
|
||||
websocket_service = hey_joe.WebSocketService("127.0.0.1", ws_port)
|
||||
websocket_service.register_followup("states", send_states)
|
||||
websocket_service.register_followup("nodes", send_nodes)
|
||||
|
||||
#
|
||||
# Flask App
|
||||
#
|
||||
|
||||
rest_app = Flask("fleet-monitor", root_path=os.path.dirname(__file__))
|
||||
|
||||
@rest_app.route("/")
|
||||
def status():
|
||||
template_path = os.path.join('monitor.html')
|
||||
return render_template(template_path)
|
||||
|
||||
#
|
||||
# Server
|
||||
#
|
||||
|
||||
deployer = HendrixDeploy(action="start", options={"wsgi": rest_app, "http_port": http_port})
|
||||
deployer.add_non_tls_websocket_service(websocket_service)
|
||||
|
||||
click.secho(f"Running Moe on 127.0.0.1:{http_port}")
|
||||
|
||||
if not dry_run:
|
||||
deployer.run()
|
||||
monitor.start(http_port=http_port, ws_port=ws_port, dry_run=dry_run)
|
||||
|
|
Loading…
Reference in New Issue