Skip to content

Commit

Permalink
Implement online_dc again
Browse files Browse the repository at this point in the history
  • Loading branch information
Thor77 committed Sep 8, 2017
1 parent 90a367d commit 91a9b8e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tsstats/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# TODO: Implemented online_dc again
import itertools
import logging
import re
Expand Down Expand Up @@ -125,17 +124,25 @@ def parse_logs(log_glob, ident_map=None, online_dc=True, *args, **kwargs):
'''
for virtualserver_id, logs in _bundle_logs(glob(log_glob)).items():
clients = Clients(ident_map)
for log in logs:
for index, log in enumerate(logs):
with open(log.path, encoding='utf-8') as f:
# parse logfile line by line and filter lines without events
events = filter(None, map(_parse_line, f))
# chain apply events to Client-obj
clients.apply_events(itertools.chain.from_iterable(events))
# warn for online clients

# find connected clients
online_clients = list(filter(lambda c: c.connected, clients))

logger.debug(
'Some clients are still connected: %s' % online_clients
'Some clients are still connected: %s', online_clients
)
if index == len(logs) - 1 and online_dc:
logger.debug('Last log => disconnecting online clients')
# last iteration => disconnect online clients if desired
for online_client in online_clients:
online_client.disconnect(pendulum.utcnow())
online_client.connected += 1
if len(clients) >= 1:
# assemble Server-obj and yield
yield Server(virtualserver_id, clients)

0 comments on commit 91a9b8e

Please sign in to comment.