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

Method _execute

gunicorn/dirty/stash.py:137–185  ·  view source on GitHub ↗

Execute a stash operation. Args: op: Operation code (STASH_OP_*) table: Table name key: Optional key value: Optional value pattern: Optional pattern for keys operation Returns: Result from the operatio

(self, op, table, key=None, value=None, pattern=None)

Source from the content-addressed store, hash-verified

135 self._sock = None
136
137 def _execute(self, op, table, key=None, value=None, pattern=None):
138 """
139 Execute a stash operation.
140
141 Args:
142 op: Operation code (STASH_OP_*)
143 table: Table name
144 key: Optional key
145 value: Optional value
146 pattern: Optional pattern for keys operation
147
148 Returns:
149 Result from the operation
150 """
151 with self._lock:
152 if self._sock is None:
153 self._connect()
154
155 request_id = self._get_request_id()
156 message = make_stash_message(
157 request_id, op, table,
158 key=key, value=value, pattern=pattern
159 )
160
161 try:
162 DirtyProtocol.write_message(self._sock, message)
163 response = DirtyProtocol.read_message(self._sock)
164
165 msg_type = response.get("type")
166 if msg_type == DirtyProtocol.MSG_TYPE_RESPONSE:
167 return response.get("result")
168 elif msg_type == DirtyProtocol.MSG_TYPE_ERROR:
169 error_info = response.get("error", {})
170 error_type = error_info.get("error_type", "StashError")
171 error_msg = error_info.get("message", "Unknown error")
172
173 if error_type == "StashTableNotFoundError":
174 raise StashTableNotFoundError(table)
175 if error_type == "StashKeyNotFoundError":
176 raise StashKeyNotFoundError(table, key)
177 raise StashError(error_msg)
178 else:
179 raise StashError(f"Unexpected response type: {msg_type}")
180
181 except Exception as e:
182 self._close()
183 if isinstance(e, StashError):
184 raise
185 raise StashError(f"Stash operation failed: {e}") from e
186
187 # -------------------------------------------------------------------------
188 # Public API

Callers 10

putMethod · 0.95
getMethod · 0.95
deleteMethod · 0.95
keysMethod · 0.95
clearMethod · 0.95
infoMethod · 0.95
ensureMethod · 0.95
existsMethod · 0.95
delete_tableMethod · 0.95
tablesMethod · 0.95

Calls 10

_connectMethod · 0.95
_get_request_idMethod · 0.95
_closeMethod · 0.95
make_stash_messageFunction · 0.85
StashErrorClass · 0.85
write_messageMethod · 0.45
read_messageMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected