-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
73 lines (47 loc) · 1.71 KB
/
app.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
65
66
67
68
69
70
71
72
73
import os
import signal
import sys
from prometheus_client import start_http_server
from threading import Event
from rasa.constants import DEFAULT_RASA_PORT
from sanic.log import LOGGING_CONFIG_DEFAULTS
from common import logging
from common.config import app
from rasa.__main__ import main as rasa_main
logger = None
event = Event()
def start_prometheus():
start_http_server(app.prometheus_port)
def handle_signal(signal, frame):
event.set()
signal.signal(signal.SIGTERM, handle_signal)
def set_endpoints_config_variables():
os.environ["ACTIONS_ENDPOINT_URL"] = app.actions_url + "/webhook"
os.environ["TRACKER_STORE_TYPE"] = app.tracker_store_type
os.environ["DB_HOSTNAME"] = app.database_host or ""
os.environ["DB_PORT"] = (
str(app.database_port) if app.database_port is not None else ""
)
os.environ["DB_NAME"] = app.database_name or ""
os.environ["DB_USERNAME"] = app.database_user or ""
os.environ["DB_PASSWORD"] = app.database_password or ""
os.environ["LOCK_STORE_TYPE"] = app.lock_store_type
os.environ["REDIS_HOSTNAME"] = app.redis_hostname or ""
os.environ["REDIS_PORT"] = str(app.redis_port) if app.redis_port is not None else ""
os.environ["REDIS_DB"] = "1"
def main():
global logger
logger = logging.initialize_logging()
logger.info("Starting Astro")
app.log_config()
set_endpoints_config_variables()
if app.prometheus is True:
start_prometheus()
# Use API_PORT when set to other than default
if app.api_port != DEFAULT_RASA_PORT:
sys.argv.extend(["--port", str(app.api_port)])
if app.log_level == "DEBUG":
sys.argv.extend(["--debug"])
rasa_main()
if __name__ == "__main__":
main()