Mercurial > piecrust2
comparison foodtruck/pubutil.py @ 609:978d8bca9fb3
admin: Fix "Publish started" message showing up multiple times.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 28 Jan 2016 22:16:47 -0800 |
parents | c6bc0ef03f82 |
children | e2e955a3bb25 |
comparison
equal
deleted
inserted
replaced
608:8e1b38632702 | 609:978d8bca9fb3 |
---|---|
27 lambda *args: _shutdown_server_and_raise_sigint()) | 27 lambda *args: _shutdown_server_and_raise_sigint()) |
28 | 28 |
29 | 29 |
30 class PublishLogReader(object): | 30 class PublishLogReader(object): |
31 _pub_max_time = 10 * 60 # Don't bother about pubs older than 10mins. | 31 _pub_max_time = 10 * 60 # Don't bother about pubs older than 10mins. |
32 _poll_interval = 2 # Check the PID file every 2 seconds. | 32 _poll_interval = 1 # Check the PID file every 1 seconds. |
33 _ping_interval = 30 # Send a ping message every 30 seconds. | 33 _ping_interval = 30 # Send a ping message every 30 seconds. |
34 | 34 |
35 def __init__(self, pid_path, log_path): | 35 def __init__(self, pid_path, log_path): |
36 self.pid_path = pid_path | 36 self.pid_path = pid_path |
37 self.log_path = log_path | 37 self.log_path = log_path |
38 self._pub_pid_mtime = 0 | 38 self._pub_pid_mtime = 0 |
39 self._last_seek = 0 | 39 self._last_seek = -1 |
40 self._last_ping_time = 0 | 40 self._last_ping_time = 0 |
41 | 41 |
42 def run(self): | 42 def run(self): |
43 logger.debug("Opening publish log...") | 43 logger.debug("Opening publish log...") |
44 | 44 |
62 self._pub_pid_mtime = 0 | 62 self._pub_pid_mtime = 0 |
63 | 63 |
64 # Send data. | 64 # Send data. |
65 new_data = None | 65 new_data = None |
66 if self._pub_pid_mtime > 0 or prev_mtime > 0: | 66 if self._pub_pid_mtime > 0 or prev_mtime > 0: |
67 if self._last_seek == 0: | 67 if self._last_seek < 0: |
68 outstr = 'event: message\ndata: Publish started.\n\n' | 68 outstr = 'event: message\ndata: Publish started.\n\n' |
69 yield bytes(outstr, 'utf8') | 69 yield bytes(outstr, 'utf8') |
70 self._last_seek = 0 | |
70 | 71 |
71 try: | 72 try: |
72 with open(self.log_path, 'r', encoding='utf8') as fp: | 73 with open(self.log_path, 'r', encoding='utf8') as fp: |
73 fp.seek(self._last_seek) | 74 fp.seek(self._last_seek) |
74 new_data = fp.read() | 75 new_data = fp.read() |