MCPcopy
hub / github.com/benoitc/gunicorn / _send_manage_message

Method _send_manage_message

gunicorn/ctl/handlers.py:350–417  ·  view source on GitHub ↗

Send a worker management message to the dirty arbiter. Args: operation: "add" or "remove" count: Number of workers to add/remove Returns: Dictionary with result or error

(self, operation: str, count: int)

Source from the content-addressed store, hash-verified

348 return self._send_manage_message("remove", count)
349
350 def _send_manage_message(self, operation: str, count: int) -> dict:
351 """
352 Send a worker management message to the dirty arbiter.
353
354 Args:
355 operation: "add" or "remove"
356 count: Number of workers to add/remove
357
358 Returns:
359 Dictionary with result or error
360 """
361 # Get socket path from arbiter object or environment
362 dirty_socket_path = None
363 if hasattr(self.arbiter, 'dirty_arbiter') and self.arbiter.dirty_arbiter:
364 dirty_socket_path = getattr(
365 self.arbiter.dirty_arbiter, 'socket_path', None
366 )
367 if not dirty_socket_path:
368 dirty_socket_path = os.environ.get('GUNICORN_DIRTY_SOCKET')
369 if not dirty_socket_path:
370 return {
371 "success": False,
372 "error": "Cannot find dirty arbiter socket path",
373 }
374
375 try:
376 from gunicorn.dirty.protocol import (
377 DirtyProtocol, MANAGE_OP_ADD, MANAGE_OP_REMOVE
378 )
379
380 op = MANAGE_OP_ADD if operation == "add" else MANAGE_OP_REMOVE
381
382 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
383 sock.settimeout(10.0)
384 sock.connect(dirty_socket_path)
385
386 # Send manage request
387 request = {
388 "type": DirtyProtocol.MSG_TYPE_MANAGE,
389 "id": 1,
390 "op": op,
391 "count": count,
392 }
393 DirtyProtocol.write_message(sock, request)
394
395 # Read response
396 response = DirtyProtocol.read_message(sock)
397 sock.close()
398
399 if response.get("type") == DirtyProtocol.MSG_TYPE_RESPONSE:
400 return response.get("result", {"success": True})
401 elif response.get("type") == DirtyProtocol.MSG_TYPE_ERROR:
402 error = response.get("error", {})
403 return {
404 "success": False,
405 "error": error.get("message", str(error)),
406 }
407 else:

Callers 2

dirty_addMethod · 0.95
dirty_removeMethod · 0.95

Calls 6

getMethod · 0.45
settimeoutMethod · 0.45
connectMethod · 0.45
write_messageMethod · 0.45
read_messageMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected