-
Notifications
You must be signed in to change notification settings - Fork 0
/
processes.py
55 lines (39 loc) · 1.41 KB
/
processes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import threading
from mq import AbstractQueue, TickQueue
from schema import Tick
from db import AbstractDB, consoleDB
class ProducerThread(threading.Thread):
def __init__(self):
super().__init__()
class ConsumerThread(threading.Thread):
def __init__(self):
super().__init__()
class WriterEnqueueThread(ProducerThread):
def __init__(self, item, queue):
assert isinstance(queue, AbstractQueue)
super().__init__()
class TickWriterDefaultEnqueueThread(WriterEnqueueThread):
def __init__(self, item, queue):
super().__init__(item=item, queue=queue)
assert isinstance(queue, TickQueue)
assert isinstance(item, Tick)
self.tick = item
self.mq = queue
def run(self):
self.mq.enqueue(self.tick)
class WriterDequeueThread(ConsumerThread):
def __init__(self, queue, db):
assert isinstance(queue, AbstractQueue)
assert isinstance(db, AbstractDB)
super().__init__()
class TickWriterDefaultDequeueThread(WriterDequeueThread):
def __init__(self, queue, db):
super().__init__(queue,db)
assert isinstance(queue, TickQueue)
self.mq = queue
self.db = db
def run(self):
while True:
tick = self.mq.dequeue()
assert isinstance(tick, Tick)
self.db.write(tick)