mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-09-20 16:08:30 +00:00
Stop regexp processing after timeput (60sec)
Minor pep8 fixes
This commit is contained in:
parent
a414a84044
commit
6d199f0150
1 changed files with 36 additions and 16 deletions
|
@ -9,20 +9,29 @@ supplied in the term webpage.
|
||||||
import redis
|
import redis
|
||||||
import time
|
import time
|
||||||
from pubsublogger import publisher
|
from pubsublogger import publisher
|
||||||
from packages import lib_words
|
|
||||||
from packages import Paste
|
from packages import Paste
|
||||||
import os
|
|
||||||
from os import environ
|
|
||||||
import datetime
|
|
||||||
import calendar
|
import calendar
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
|
import time
|
||||||
from Helper import Process
|
from Helper import Process
|
||||||
|
|
||||||
# Email notifications
|
# Email notifications
|
||||||
from NotificationHelper import *
|
from NotificationHelper import *
|
||||||
|
|
||||||
|
|
||||||
|
class TimeoutException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def timeout_handler(signum, frame):
|
||||||
|
raise TimeoutException
|
||||||
|
|
||||||
|
signal.signal(signal.SIGALRM, timeout_handler)
|
||||||
|
|
||||||
|
|
||||||
# Config Variables
|
# Config Variables
|
||||||
DICO_REFRESH_TIME = 60 # s
|
DICO_REFRESH_TIME = 60 # s
|
||||||
|
PROCESS_TIMEOUT = 60
|
||||||
|
|
||||||
BlackListTermsSet_Name = "BlackListSetTermSet"
|
BlackListTermsSet_Name = "BlackListSetTermSet"
|
||||||
TrackedTermsSet_Name = "TrackedSetTermSet"
|
TrackedTermsSet_Name = "TrackedSetTermSet"
|
||||||
|
@ -38,6 +47,7 @@ top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, to
|
||||||
# create direct link in mail
|
# create direct link in mail
|
||||||
full_paste_url = "/showsavedpaste/?paste="
|
full_paste_url = "/showsavedpaste/?paste="
|
||||||
|
|
||||||
|
|
||||||
def refresh_dicos():
|
def refresh_dicos():
|
||||||
dico_regex = {}
|
dico_regex = {}
|
||||||
dico_regexname_to_redis = {}
|
dico_regexname_to_redis = {}
|
||||||
|
@ -91,7 +101,17 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# iterate the word with the regex
|
# iterate the word with the regex
|
||||||
for regex_str, compiled_regex in dico_regex.items():
|
for regex_str, compiled_regex in dico_regex.items():
|
||||||
|
|
||||||
|
signal.alarm(PROCESS_TIMEOUT)
|
||||||
|
try:
|
||||||
matched = compiled_regex.search(content)
|
matched = compiled_regex.search(content)
|
||||||
|
except TimeoutException:
|
||||||
|
log_msg = "{0} processing timeout".format(filename)
|
||||||
|
print (log_msg)
|
||||||
|
publisher.critical(log_msg)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
signal.alarm(0)
|
||||||
|
|
||||||
if matched is not None: # there is a match
|
if matched is not None: # there is a match
|
||||||
print('regex matched {}'.format(regex_str))
|
print('regex matched {}'.format(regex_str))
|
||||||
|
|
Loading…
Reference in a new issue