-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (37 loc) · 1.24 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
# tornado imports
from tornado.ioloop import IOLoop
from tornado.queues import Queue
from tornado import gen
from tornado.options import define, parse_command_line, options
# local imports
from clients.infrastructure_bots import telegram_bot, slack_bot
from clients.controllers import mirror_controller
# define ports input to be set by command line argument
define('port', default=6003, help='port to launch process')
# @gen.coroutine
def main():
#get port from commandline
parse_command_line()
# create service components
q = {
'dispatch_telegram': Queue(),
'dispatch_slack': Queue(),
'income': Queue()
}
controller = mirror_controller(q=q)
telegram_ai = telegram_bot(q=q)
slack_ai = slack_bot(q=q)
# Start workers without waiting (since it never finishes).
IOLoop.current().spawn_callback(controller.main_loop)
IOLoop.current().spawn_callback(telegram_ai.dispatcher)
IOLoop.current().spawn_callback(slack_ai.dispatcher)
#create listener instance
# configuration
port = options.port
# server
telegram_ai.service_listener.listen(port)
slack_ai.service_listener.listen(port + 1)
#launch listener server
IOLoop.instance().start()
if __name__ == '__main__':
main()