Added pause & resume

master
Ringo Wantanabe 6 years ago
parent dd16b8e3f0
commit c25b6ef82b
No known key found for this signature in database
GPG Key ID: C1C1CD34CF2907B2

@ -370,6 +370,7 @@ class Daemon(threading.Thread):
self.buf = buf self.buf = buf
self.running=True self.running=True
self.info = info self.info = info
self.paused=False
threading.Thread.__init__(self) threading.Thread.__init__(self)
def _get(self,con, fr, ca=False): def _get(self,con, fr, ca=False):
if ca: if ca:
@ -403,6 +404,12 @@ class Daemon(threading.Thread):
elif cmd.uCommand == Command.CMD_INFO: #information elif cmd.uCommand == Command.CMD_INFO: #information
log("[daemon]: Recieved info") log("[daemon]: Recieved info")
con.send(json.dumps(self.info).encode("ascii")) con.send(json.dumps(self.info).encode("ascii"))
elif cmd.uCommand == Command.CMD_PAUSE:
log("[daemon]: Recieved pause")
self.paused = True
elif cmd.uCommand == Command.CMD_RESUME:
log("[daemon]: Recieved resume")
self.paused = False
else: #unknwon command else: #unknwon command
log("[daemon]: Recieved unknown command") log("[daemon]: Recieved unknown command")
pass pass
@ -466,16 +473,20 @@ if args.daemon!=None:
try: try:
while runForever or daemon.running: while runForever or daemon.running:
log("Reading threads for %s from %d" % (args.board, last))
posts = parse_page(args.api, args.board, "1", last) if(not runForever) and daemon.paused:
last = pnomax(last, posts) log("Skipping rotation")
if(len(posts)>0):
log("\t%d new posts since last cycle" % len(posts))
buffer_write(buf, posts)
else: else:
log("\tnothing new") log("Reading threads for %s from %d" % (args.board, last))
log("Buffer written successfully") posts = parse_page(args.api, args.board, "1", last)
last = pnomax(last, posts)
if(len(posts)>0):
log("\t%d new posts since last cycle" % len(posts))
buffer_write(buf, posts)
else:
log("\tnothing new")
log("Buffer written successfully")
time.sleep(int(args.timeout)) time.sleep(int(args.timeout))
except(KeyboardInterrupt): except(KeyboardInterrupt):

@ -28,6 +28,8 @@ def parsecmd(s):
elif s=="clear": return Command.CMD_CLEAR elif s=="clear": return Command.CMD_CLEAR
elif s=="get-clear": return Command.CMD_GET_CLEAR elif s=="get-clear": return Command.CMD_GET_CLEAR
elif s=="info": return Command.CMD_INFO elif s=="info": return Command.CMD_INFO
elif s=="pause": return Command.CMD_PAUSE
elif s=="resume": return Command.CMD_RESUME
else: return None else: return None
parser = argparse.ArgumentParser(description="rtbwpy daemon control.") parser = argparse.ArgumentParser(description="rtbwpy daemon control.")

@ -29,6 +29,8 @@ class Command(object):
CMD_SHUTDOWN = 3 CMD_SHUTDOWN = 3
CMD_GET_CLEAR = 4 CMD_GET_CLEAR = 4
CMD_INFO = 5 CMD_INFO = 5
CMD_PAUSE = 6
CMD_RESUME = 7
def __init__(self): def __init__(self):
self.uCommand = 0 self.uCommand = 0

Loading…
Cancel
Save