/
FileProcessorThread.py
54 lines (42 loc) · 1.47 KB
/
FileProcessorThread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python3
import _thread
import time
import json
import traceback
# Define a function for the thread
from DBHandler import DBHandler
from FileProcessor import FileProcessor
def process( threadName ):
while True:
with open('configurations.json') as f:
data = json.load(f)
DATABASEIP = data["DATABASEIP"]
DB_USER = data["DB_USER"]
DB_PASSWORD = data["DB_PASSWORD"]
DATABASE = data["DATABASE"]
THREAD_SLEEP_TIME = data["THREAD_SLEEP_TIME"]
DBHandler_ = DBHandler(DATABASEIP,DB_USER,DB_PASSWORD,DATABASE)
fileList =[]
try:
fileList = DBHandler_.getFilesToProcess()
print("Going to process"+str(len(fileList))+"files")
try:
for file_ in fileList:
FileProcessor_ = FileProcessor()
FileProcessor_.process(file_)
except Exception as e:
print("Error in File Processing Thread" + str(e))
print(traceback.format_exc())
DBHandler_.updateFileStatus(file_.FileName, "F")
except Exception as e:
print("Error in File Processing Thread"+str(e))
print(traceback.format_exc())
print (threadName +"going to sleep for "+ str(THREAD_SLEEP_TIME))
time.sleep(THREAD_SLEEP_TIME)
# Create two threads as follows
try:
_thread.start_new_thread( process, ("FileProcessingThread", ) )
except:
print ("Error: unable to start thread")
while 1:
pass