-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.py
52 lines (42 loc) · 1.7 KB
/
index.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
""" Tornado Web Server Starting Script - Application Entry Point """
import logging
from threading import Thread
from aiocron import crontab
from biothings.web.launcher import main
from filelock import FileLock, Timeout
from tornado.options import define, options
from discovery.handlers import HANDLERS
from discovery.notify import update_n3c_routine
from discovery.utils.backup import daily_backup_routine
from discovery.utils.coverage import daily_coverage_update
from discovery.utils.update import daily_schema_update
define("proxy_url", default="http://localhost:3000/", help="localhost port serving frontend")
# Create a lock can only be acquired by one process.
# Make sure only one process should perform backup routines
_lock = FileLock(".lock", timeout=0)
def routine():
logger = logging.getLogger("routine")
try:
_lock.acquire()
logger.info("Schedule lock acquired successfully.")
except Timeout:
logger.warning("Schedule lock acquired by another process. No need to run it in this process.")
else:
logger.info("update_n3c_routine()")
update_n3c_routine()
logger.info("daily_backup_routine()")
daily_backup_routine()
logger.info("daily_schema_update()")
daily_schema_update()
logger.info("daily_coverage_update()")
daily_coverage_update()
_lock.release()
logger.info("Schedule lock released successfully.")
def run_routine():
thread = Thread(target=routine, daemon=True)
thread.start()
if __name__ == "__main__":
options.parse_command_line()
if not options.debug:
crontab("0 0 * * *", func=run_routine, start=True) # run daily at mid-night
main(HANDLERS, use_curl=True)