-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoresd.py
64 lines (52 loc) · 1.49 KB
/
scoresd.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
55
56
57
58
59
60
61
62
63
64
import MySQLdb
import scload
import time
import crawl_utils
import sys
import query
import logging
from logging import debug, info, warn, error
import pagedefs
# Can run as a daemon and tail a number of logfiles and milestones and
# update the db.
def interval_work(cursor, interval, master):
master.tail_all(cursor)
def tail_logfiles(logs, milestones, interval=60):
db = scload.connect_db()
scload.init_listeners(db)
cursor = db.cursor()
scload.set_active_cursor(cursor)
elapsed_time = 0
master = scload.create_master_reader()
scload.bootstrap_known_raceclasses(cursor)
try:
while True:
try:
interval_work(cursor, interval, master)
pagedefs.incremental_build(cursor)
if not interval:
break
except IOError, e:
error("IOError: %s" % e)
time.sleep(interval)
elapsed_time += interval
pagedefs.tick_dirty()
if crawl_utils.scoresd_stop_requested():
info("Exit due to scoresd stop request.")
break
finally:
scload.set_active_cursor(None)
cursor.close()
db.close()
if __name__ == '__main__':
daemon = "-n" not in sys.argv
logformat = crawl_utils.LOGFORMAT
if daemon:
logging.basicConfig(level=logging.DEBUG,
filename = crawl_utils.LOGFILE,
format = logformat)
else:
logging.basicConfig(level=logging.DEBUG, format = logformat)
if daemon:
crawl_utils.daemonize()
tail_logfiles( scload.LOGS, scload.MILESTONES, 60 )