forked from xai-org/x-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (44 loc) · 1.34 KB
/
Copy pathmain.py
File metadata and controls
54 lines (44 loc) · 1.34 KB
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
import signal
import asyncio
import logging
from grox.engine import Engine
from grox.service import GrpcServer
from grox.dispatcher import Dispatcher
from grox.config.config import grox_config
from grox.schedules.init import init_proc
from grox.schedules.context import (
cleanup,
new_context,
shutdown_context,
queue_connection_shutdown_context,
)
logger = logging.getLogger(__name__)
shutdown = asyncio.Event()
async def serve():
await init_proc("main")
logger.info(f"Starting grox server...")
context = new_context()
engine = Engine(context)
dispatcher = Dispatcher(context)
grpc_server = GrpcServer(context)
await engine.start()
await dispatcher.start()
await grpc_server.start()
logger.info("Grox server started")
event_loop = asyncio.get_running_loop()
event_loop.add_signal_handler(signal.SIGINT, lambda: shutdown.set())
event_loop.add_signal_handler(signal.SIGTERM, lambda: shutdown.set())
await shutdown.wait()
logger.warning("Grox server shutting down...")
queue_connection_shutdown_context(context)
await asyncio.sleep(300)
shutdown_context(context)
await asyncio.gather(
grpc_server.stop(),
dispatcher.stop(),
engine.stop(),
)
cleanup()
logger.warning("Grox server stopped")
if __name__ == "__main__":
asyncio.run(serve())