Zakha123-cyber commited on
Commit
ec0e6ae
·
1 Parent(s): 9bbc5a7

Fix: Add Redis timeout config + subprocess text mode

Browse files
Files changed (2) hide show
  1. app/core/redis_client.py +5 -1
  2. start.py +8 -4
app/core/redis_client.py CHANGED
@@ -23,7 +23,11 @@ class RedisClient:
23
  self._connection_pool = redis.ConnectionPool.from_url(
24
  settings.REDIS_URL,
25
  decode_responses=True,
26
- max_connections=10
 
 
 
 
27
  )
28
 
29
  self._client = redis.Redis(connection_pool=self._connection_pool)
 
23
  self._connection_pool = redis.ConnectionPool.from_url(
24
  settings.REDIS_URL,
25
  decode_responses=True,
26
+ max_connections=10,
27
+ socket_connect_timeout=30, # 30s untuk SSL handshake
28
+ socket_timeout=30, # 30s untuk operasi I/O
29
+ socket_keepalive=True, # Keep connection alive
30
+ health_check_interval=30 # Check health tiap 30s
31
  )
32
 
33
  self._client = redis.Redis(connection_pool=self._connection_pool)
start.py CHANGED
@@ -10,9 +10,9 @@ from loguru import logger
10
 
11
  def stream_output(process, prefix):
12
  """Stream subprocess output to main stdout"""
13
- for line in iter(process.stdout.readline, b''):
14
  if line:
15
- print(f"[{prefix}] {line.decode().rstrip()}")
16
  process.stdout.close()
17
 
18
  def main():
@@ -25,7 +25,9 @@ def main():
25
  [sys.executable, "-m", "app.worker"],
26
  stdout=subprocess.PIPE,
27
  stderr=subprocess.STDOUT,
28
- bufsize=1
 
 
29
  )
30
  logger.info(f"✓ Worker started (PID: {worker_process.pid})")
31
 
@@ -46,7 +48,9 @@ def main():
46
  [sys.executable, "-m", "app.main"],
47
  stdout=subprocess.PIPE,
48
  stderr=subprocess.STDOUT,
49
- bufsize=1
 
 
50
  )
51
  logger.info(f"✓ API server started (PID: {api_process.pid})")
52
 
 
10
 
11
  def stream_output(process, prefix):
12
  """Stream subprocess output to main stdout"""
13
+ for line in iter(process.stdout.readline, ''):
14
  if line:
15
+ print(f"[{prefix}] {line.rstrip()}", flush=True)
16
  process.stdout.close()
17
 
18
  def main():
 
25
  [sys.executable, "-m", "app.worker"],
26
  stdout=subprocess.PIPE,
27
  stderr=subprocess.STDOUT,
28
+ text=True, # TEXT MODE (bukan binary)
29
+ bufsize=1, # Line buffering (works with text mode)
30
+ universal_newlines=True
31
  )
32
  logger.info(f"✓ Worker started (PID: {worker_process.pid})")
33
 
 
48
  [sys.executable, "-m", "app.main"],
49
  stdout=subprocess.PIPE,
50
  stderr=subprocess.STDOUT,
51
+ text=True, # TEXT MODE (bukan binary)
52
+ bufsize=1, # Line buffering (works with text mode)
53
+ universal_newlines=True
54
  )
55
  logger.info(f"✓ API server started (PID: {api_process.pid})")
56