|
@@ -20,8 +20,8 @@ |
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
# SOFTWARE. |
|
|
# SOFTWARE. |
|
|
|
|
|
|
|
|
from collections import deque |
|
|
|
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
|
|
|
from Queue import Queue |
|
|
from threading import Thread |
|
|
from threading import Thread |
|
|
|
|
|
|
|
|
from earwigbot.commands import Command |
|
|
from earwigbot.commands import Command |
|
@@ -51,7 +51,7 @@ class RCMonitor(Command): |
|
|
self._levels = {} |
|
|
self._levels = {} |
|
|
self._issues = {} |
|
|
self._issues = {} |
|
|
self._descriptions = {} |
|
|
self._descriptions = {} |
|
|
self._queue = deque() |
|
|
|
|
|
|
|
|
self._queue = Queue() |
|
|
|
|
|
|
|
|
self._thread = Thread(target=self._callback, name="rc_monitor") |
|
|
self._thread = Thread(target=self._callback, name="rc_monitor") |
|
|
self._thread.daemon = True |
|
|
self._thread.daemon = True |
|
@@ -67,8 +67,8 @@ class RCMonitor(Command): |
|
|
|
|
|
|
|
|
def process(self, data): |
|
|
def process(self, data): |
|
|
if isinstance(data, RC): |
|
|
if isinstance(data, RC): |
|
|
newlen = len(self._queue) + 1 |
|
|
|
|
|
self._queue.append(data) |
|
|
|
|
|
|
|
|
newlen = self._queue.qsize() + 1 |
|
|
|
|
|
self._queue.put(data) |
|
|
if newlen > self._stats["max_backlog"]: |
|
|
if newlen > self._stats["max_backlog"]: |
|
|
self._stats["max_backlog"] = newlen |
|
|
self._stats["max_backlog"] = newlen |
|
|
return |
|
|
return |
|
@@ -82,14 +82,13 @@ class RCMonitor(Command): |
|
|
rate = self._stats["edits"] / seconds |
|
|
rate = self._stats["edits"] / seconds |
|
|
msg = ("\x02{edits:,}\x0F edits checked since {since} " |
|
|
msg = ("\x02{edits:,}\x0F edits checked since {since} " |
|
|
"(\x02{rate:.2f}\x0F edits/sec); \x02{hits:,}\x0F hits; " |
|
|
"(\x02{rate:.2f}\x0F edits/sec); \x02{hits:,}\x0F hits; " |
|
|
"\x02{backlog:,}\x0F-edit backlog (\x02{max_backlog:,}\x0F " |
|
|
|
|
|
"max).") |
|
|
|
|
|
|
|
|
"\x02{qsize:,}\x0F-edit backlog (\x02{max_backlog:,}\x0F max).") |
|
|
self.reply(data, msg.format( |
|
|
self.reply(data, msg.format( |
|
|
since=since, rate=rate, backlog=len(self._queue), **self._stats)) |
|
|
|
|
|
|
|
|
since=since, rate=rate, qsize=self._queue.qsize(), **self._stats)) |
|
|
|
|
|
|
|
|
def unload(self): |
|
|
def unload(self): |
|
|
self._thread.running = False |
|
|
self._thread.running = False |
|
|
self._queue.append(None) |
|
|
|
|
|
|
|
|
self._queue.put(None) |
|
|
|
|
|
|
|
|
def _prepare_reports(self): |
|
|
def _prepare_reports(self): |
|
|
"""Set up internal tables for storing report information.""" |
|
|
"""Set up internal tables for storing report information.""" |
|
@@ -158,7 +157,7 @@ class RCMonitor(Command): |
|
|
def _callback(self): |
|
|
def _callback(self): |
|
|
"""Internal callback for the RC monitor thread.""" |
|
|
"""Internal callback for the RC monitor thread.""" |
|
|
while self._thread.running: |
|
|
while self._thread.running: |
|
|
event = self._queue.popleft() |
|
|
|
|
|
|
|
|
event = self._queue.get() |
|
|
if not self._thread.running: |
|
|
if not self._thread.running: |
|
|
break |
|
|
break |
|
|
self._handle_event(event) |
|
|
self._handle_event(event) |