Commit eb31b078 by Owo Sugiana

Bug fixed thread di Windows

1 parent ffcd6afc
......@@ -44,23 +44,24 @@ class Pantau(FileSystemEventHandler):
set_log_file(event.src_path)
def save_log(line):
line = line.rstrip()
match = REGEX.search(line)
if not match:
return
print([line])
db_session = my_registry['db_session']
line_id = sha256(line.encode('utf-8')).hexdigest()
row = LogFile(line_id=line_id, line=line)
try:
with transaction.manager:
db_session.add(row)
except IntegrityError:
return
def read_log(log_file, db_url):
def save_log(line):
line = line.rstrip()
match = REGEX.search(line)
if not match:
return
print([line])
line_id = sha256(line.encode('utf-8')).hexdigest()
row = LogFile(line_id=line_id, line=line)
try:
with transaction.manager:
db_session.add(row)
except IntegrityError:
return
def read_log(log_file):
engine = create_engine(db_url)
factory = sessionmaker(bind=engine)
db_session = factory()
with BacaFile(log_file) as f:
while True:
line = f.readline()
......@@ -78,10 +79,7 @@ def main(argv=sys.argv[1:]):
option = pars.parse_args(argv)
conf = ConfigParser()
conf.read(option.conf)
engine = create_engine(conf.get('main', 'db_url'))
factory = sessionmaker(bind=engine)
my_registry['db_session'] = db_session = factory()
register(db_session)
db_url = conf.get('main', 'db_url')
log_dir = conf.get('main', 'log_dir')
handler = Pantau()
observer = Observer()
......@@ -98,7 +96,7 @@ def main(argv=sys.argv[1:]):
log_file = my_registry['log_file']
del my_registry['log_file']
my_registry['last_log_file'] = log_file
thread = Process(target=read_log, args=(log_file,))
thread = Process(target=read_log, args=(log_file, db_url))
my_registry['read_log'] = thread
print('Start read file ...')
thread.start()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!