MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / run_worker

Function run_worker

src/codegraphcontext/core/falkor_worker.py:44–177  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42 return 6379
43
44def run_worker():
45
46 db_path = os.getenv('FALKORDB_PATH')
47 socket_path = os.getenv('FALKORDB_SOCKET_PATH')
48 port = get_falkordb_port(socket_path)
49
50 global db_instance
51
52 # Get configuration from env
53 if not db_path or not socket_path:
54 logger.error("Missing configuration. FALKORDB_PATH and FALKORDB_SOCKET_PATH must be set.")
55 sys.exit(1)
56
57 if is_port_in_use("127.0.0.1", port):
58 logger.warning(f"Port {port} already in use. Checking FalkorDB instance...")
59
60 try:
61 from falkordb import FalkorDB
62
63 client = FalkorDB(unix_socket_path=socket_path)
64 test_graph = client.select_graph("__cgc_health_check")
65 test_graph.query("RETURN 1")
66
67 logger.info("Valid FalkorDB already running. Exiting worker.")
68 sys.exit(0)
69
70 except Exception as e:
71 logger.error(
72 f"Port {port} is already occupied by another service and cannot be reused by FalkorDB. "
73 f"Please stop the conflicting service or configure a different port. "
74 f"Underlying error: {e}"
75 )
76 sys.exit(1)
77
78 # Ensure dir exists
79 Path(db_path).parent.mkdir(parents=True, exist_ok=True)
80
81 logger.info(f"Starting FalkorDB Lite worker...")
82 logger.info(f"DB Path: {db_path}")
83 logger.info(f"Socket: {socket_path}")
84
85 try:
86 import platform
87
88 if platform.system() == "Windows":
89 raise RuntimeError(
90 "CodeGraphContext uses redislite/FalkorDB, which does not support Windows.\n"
91 "Please run the project using WSL or Docker."
92 )
93
94 from redislite.falkordb_client import FalkorDB
95
96 # Determine module path for frozen bundles
97 server_config = {}
98 if getattr(sys, 'frozen', False):
99 mei_pass = getattr(sys, '_MEIPASS', os.path.dirname(sys.executable))
100 exe_dir = os.path.dirname(sys.executable)
101

Callers 2

cgc_entry.pyFile · 0.90
falkor_worker.pyFile · 0.85

Calls 6

get_falkordb_portFunction · 0.85
is_port_in_useFunction · 0.85
errorMethod · 0.80
infoMethod · 0.80
removeMethod · 0.80
queryMethod · 0.65

Tested by

no test coverage detected