def test_register_callback(): c = Cluster(1234) tmp = [] @c.register(TestMessage) def handle_hello(message, connection): tmp.append(1) c.dispatch(TestMessage(id=1)) assert tmp == [1]
import argparse import logging logging.basicConfig(level=logging.INFO) from stoopid.cluster import Cluster parser = argparse.ArgumentParser(description="Stoopid Cluster") parser.add_argument("-s", dest="seeds", metavar="seeds", nargs="+", help="seed host:port of existing informant") parser.add_argument("-i", dest="informant", metavar="informant", nargs="+", type=int, required=True) cli = parser.parse_args() logging.info("Starting cluster.") c = Cluster(int(cli.informant[0])) if not cli.seeds: c.start() else: (ip, port) = cli.seeds[0].split(":") c.join(ip, port) logging.info("Cluster started.") c.run() logging.info("Done.")