Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
grewn0uille committed Mar 7, 2018
1 parent 6407d3b commit 4cd1b8f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sherlog/log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# datetime is needed because log contains datetime object
import datetime # noqa
import os
from threading import Thread

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -75,7 +76,10 @@ def insert_log(line, dbsession, max_stop):
log = Log(**build_log(server_name, desc))
dbsession.add(log)

def insert_missing_lines(dbsession, logfile):
def insert_missing_lines():
config = get_config()
dbsession = get_session(config)
logfile = config['DEFAULT'].get('LOGFILE')
max_stop = get_max_stop(dbsession)
count = 0
with open(logfile, 'r') as fd:
Expand All @@ -88,11 +92,14 @@ def insert_missing_lines(dbsession, logfile):
dbsession.commit()


if __name__ == '__main__':
def insert_new_lines():
config = get_config()
dbsession = get_session(config)
insert_missing_lines(dbsession, config['DEFAULT'].get('LOGFILE'))
fd = LogTail(config['DEFAULT'].get('LOGFILE'))
for line in fd.tail():
insert_log(line, dbsession)
dbsession.commit()

if __name__ == '__main__':
Thread(target = insert_missing_lines).start()
Thread(target = insert_new_lines).start()

0 comments on commit 4cd1b8f

Please sign in to comment.