-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEVENT_BAR_STACK_ADD_04.py
More file actions
57 lines (51 loc) · 1.71 KB
/
EVENT_BAR_STACK_ADD_04.py
File metadata and controls
57 lines (51 loc) · 1.71 KB
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
56
57
import copy
import logging
from redisHash import StoreStack
from redisPubsub import RedisPublisher, RedisSubscriber
from pubsubKeys import PUBSUB_KEYS
from redisUtil import SetInterval
class RedisStack:
stack = []
stackCount = 0
stackLock1 = False
stackLock2 = False
def __init__(self):
# StoreStack: class to access the redis Stack.
self.subscriber = RedisSubscriber(
PUBSUB_KEYS.EVENT_BAR_STACK_ADD, None, self.addStack)
self.publisher = RedisPublisher(
PUBSUB_KEYS.EVENT_BAR_POST_TO_SERVER)
self.storeStack = StoreStack()
def sendStack(self):
stackSize = len(RedisStack.stack)
if stackSize <= 0:
return
if RedisStack.stackCount != stackSize:
RedisStack.stackCount = stackSize
RedisStack.stackLock1 = False
RedisStack.stackLock2 = False
elif RedisStack.stackLock1 and RedisStack.stackLock2:
self.publisher.publish(RedisStack.stack)
RedisStack.stack.clear()
RedisStack.stackCount = 0
RedisStack.stackLock1 = False
RedisStack.stackLock2 = False
elif RedisStack.stackLock1:
RedisStack.stackLock2 = True
else:
RedisStack.stackLock1 = True
def addStack(self, data):
RedisStack.stack.append(data)
def start(self):
try:
self.subscriber.start()
SetInterval(1, self.sendStack)
except KeyboardInterrupt:
self.subscriber.stop()
except Exception as e:
logging.error(e)
@staticmethod
def run():
logging.info("Starting RedisStack")
candidate = RedisStack()
candidate.start()