This commit is contained in:
Donald Zou
2025-09-13 08:23:54 +08:00
parent b2532e305e
commit 91a3b52a4a
15 changed files with 144 additions and 154 deletions

View File

@@ -9,6 +9,7 @@ import requests
from pydantic import BaseModel, field_serializer
import sqlalchemy as db
from .ConnectionString import ConnectionString
from flask import current_app
WebHookActions = ['peer_created', 'peer_deleted', 'peer_updated']
class WebHook(BaseModel):
@@ -173,19 +174,19 @@ class DashboardWebHooks:
if action not in WebHookActions:
return False
self.__getWebHooks()
subscribedWebHooks = filter(lambda webhook: action in webhook.SubscribedActions and webhook.IsActive, self.WebHooks)
subscribedWebHooks = filter(lambda webhook: action in webhook.SubscribedActions and webhook.IsActive,
self.WebHooks)
data['action'] = action
for i in subscribedWebHooks:
try:
ws = WebHookSession(i, data)
t = threading.Thread(target=ws.Execute, daemon=True)
t.start()
print("Spinning threads...")
current_app.logger.info(f"Requesting {i.PayloadURL}")
except Exception as e:
print(e)
current_app.logger.error(f"Requesting {i.PayloadURL} error", e)
except Exception as e:
print(e)
return True
current_app.logger.error("Error when running WebHook")
class WebHookSession:
def __init__(self, webHook: WebHook, data: dict[str, str]):