コード例 #1
0
ファイル: test_stores.py プロジェクト: def-nn/tornadose
class TestQueueStore(AsyncTestCase):
    def setUp(self):
        self.store = QueueStore()
        super(TestQueueStore, self).setUp()

    def test_submit(self):
        self.store.submit("data")
コード例 #2
0
class SystemLog:
    def __init__(self, maxsize=1000):
        self.maxsize = maxsize
        self.buffer = []
        self.q = Queue()
        self.datastore = QueueStore()
        Thread(target=self.readqueuetarget).start()

    def readqueuetarget(self):
        #https://stackoverflow.com/questions/51038793/error-happen-python3-6-while-using-tornado-in-multi-threading
        asyncio.set_event_loop(asyncio.new_event_loop())
        while True:
            li = self.q.get()
            self.buffer.append(li)
            message = json.dumps(li.toblob())
            self.datastore.submit(message)
            while len(self.buffer) > self.maxsize:
                self.buffer = self.buffer[1:]

    def log(self, li):
        self.q.put(li)

    def __repr__(self):
        return f"< systemlog < {len(self.buffer)} | {self.buffer[-50:]} > >"
コード例 #3
0
ファイル: app.py プロジェクト: dmison/pollen
import os.path
from json.decoder import JSONDecodeError

from tornado import httpserver, ioloop, web, escape
from tornado.options import define, options
from tornadose.handlers import EventSource
from tornadose.stores import QueueStore
import jwt

store = QueueStore()

define("port", default=3000, help="run on the given port", type=int)
define("debug", default=False, help="run in debug mode", type=bool)

public_key = open(os.path.abspath("id_rsa.pub"), "r").read()
private_key = open(os.path.abspath("id_rsa"), "r").read()


class ESHandler(EventSource):
    # def write_error(self, status_code, **kwargs):
    #     # e = kwargs["exc_info"]
    #     self.render("error.html")

    def get_current_user(self):
        token = self.path_args[0]
        print(token)

        try:
            token = jwt.decode(self.request.token,
                               public_key,
                               algorithm="RS256")
コード例 #4
0
ファイル: test_stores.py プロジェクト: def-nn/tornadose
 def setUp(self):
     self.store = QueueStore()
     super(TestQueueStore, self).setUp()
コード例 #5
0
 def __init__(self, maxsize=1000):
     self.maxsize = maxsize
     self.buffer = []
     self.q = Queue()
     self.datastore = QueueStore()
     Thread(target=self.readqueuetarget).start()