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

Function run_worker

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

Source from the content-addressed store, hash-verified

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

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