Fully implement WhatsApp, Signal and XMPP multiplexing
This commit is contained in:
@@ -44,6 +44,10 @@ def _runtime_command_cancel_key(service: str, command_id: str) -> str:
|
||||
return f"gia:service:command-cancel:{_service_key(service)}:{command_id}"
|
||||
|
||||
|
||||
def _runtime_command_meta_key(service: str, command_id: str) -> str:
|
||||
return f"gia:service:command-meta:{_service_key(service)}:{command_id}"
|
||||
|
||||
|
||||
def _gateway_base(service: str) -> str:
|
||||
key = f"{service.upper()}_HTTP_URL"
|
||||
default = f"http://{service}:8080"
|
||||
@@ -110,6 +114,14 @@ def enqueue_runtime_command(
|
||||
if len(queued) > 200:
|
||||
queued = queued[-200:]
|
||||
cache.set(key, queued, timeout=_RUNTIME_COMMANDS_TTL)
|
||||
cache.set(
|
||||
_runtime_command_meta_key(service_key, command_id),
|
||||
{
|
||||
"created_at": int(command.get("created_at") or int(time.time())),
|
||||
"action": str(command.get("action") or ""),
|
||||
},
|
||||
timeout=_RUNTIME_COMMANDS_TTL,
|
||||
)
|
||||
return command_id
|
||||
|
||||
|
||||
@@ -132,6 +144,7 @@ def set_runtime_command_result(
|
||||
payload = dict(result or {})
|
||||
payload.setdefault("completed_at", int(time.time()))
|
||||
cache.set(result_key, payload, timeout=_RUNTIME_COMMAND_RESULT_TTL)
|
||||
cache.delete(_runtime_command_meta_key(service_key, command_id))
|
||||
|
||||
|
||||
def cancel_runtime_command(service: str, command_id: str):
|
||||
@@ -142,9 +155,24 @@ def cancel_runtime_command(service: str, command_id: str):
|
||||
payload = {"ok": False, "error": "cancelled", "completed_at": int(time.time())}
|
||||
cache.set(result_key, payload, timeout=_RUNTIME_COMMAND_RESULT_TTL)
|
||||
cache.set(cancel_key, True, timeout=60)
|
||||
cache.delete(_runtime_command_meta_key(service_key, command_id))
|
||||
return True
|
||||
|
||||
|
||||
def runtime_command_age_seconds(service: str, command_id: str) -> float | None:
|
||||
service_key = _service_key(service)
|
||||
meta = cache.get(_runtime_command_meta_key(service_key, command_id))
|
||||
if not isinstance(meta, dict):
|
||||
return None
|
||||
try:
|
||||
created_at = int(meta.get("created_at") or 0)
|
||||
except Exception:
|
||||
created_at = 0
|
||||
if created_at <= 0:
|
||||
return None
|
||||
return max(0.0, time.time() - created_at)
|
||||
|
||||
|
||||
def cancel_runtime_commands_for_recipient(service: str, recipient: str) -> list[str]:
|
||||
"""Cancel any queued runtime commands for the given recipient and return their ids."""
|
||||
service_key = _service_key(service)
|
||||
|
||||
Reference in New Issue
Block a user