Skip to content

वेबहुक

Potato से 7 तरह की एनोटेशन घटनाओं के लिए HMAC-हस्ताक्षरित HTTP webhook सूचनाएँ भेजें — एक्सपोनेंशियल बैकऑफ़ रीट्राई, एडमिन मॉनिटरिंग, और Python/Node सत्यापन के साथ।

v2.4.0 में नया

Webhook की मदद से Potato एनोटेशन घटनाएँ होने पर बाहरी सिस्टम को ख़बर कर देता है — बिना पोलिंग के। डेटा पाइपलाइन से जुड़ें, अलर्ट चलाएँ, डैशबोर्ड अपडेट करें, या आगे की प्रोसेसिंग अपने आप शुरू करें।

अवलोकन

जब भी कोई समर्थित घटना होती है, Potato आपके कॉन्फ़िगर किए गए एंडपॉइंट पर एक HTTP POST अनुरोध भेजता है। Payload JSON में होते हैं और HMAC-SHA256 से हस्ताक्षरित रहते हैं, ताकि आप जाँच सकें कि वे आपके ही Potato instance से आए हैं।

Webhook डिलीवरी पूरी तरह नॉन-ब्लॉकिंग है — webhook के रास्ते में रहते हुए एनोटेशन अनुरोध कभी नहीं अटकते। विफल डिलीवरी एक्सपोनेंशियल बैकऑफ़ के साथ दोबारा आज़माई जाती हैं।

कॉन्फ़िगरेशन

अपने YAML कॉन्फ़िग में एक webhooks सेक्शन जोड़ें:

yaml
webhooks:
  enabled: true
  endpoints:
    - name: "my-pipeline"
      url: "https://your-system.example.com/potato-events"
      secret: "your-signing-secret"        # optional but recommended
      events:
        - annotation.created
        - item.fully_annotated
        - task.completed
      active: true
      timeout: 10

कई एंडपॉइंट

आप कई एंडपॉइंट कॉन्फ़िगर कर सकते हैं, हर एक की अलग घटना सदस्यता के साथ:

yaml
webhooks:
  enabled: true
  endpoints:
    - name: "data-pipeline"
      url: "https://pipeline.example.com/annotations"
      secret: ${WEBHOOK_SECRET_1}
      events:
        - annotation.created
        - item.fully_annotated
    - name: "slack-alerts"
      url: "https://hooks.slack.com/services/..."
      events:
        - task.completed
        - quality.attention_check_failed
    - name: "catch-all"
      url: "https://logging.example.com/potato"
      events:
        - "*"          # subscribe to all events

घटना के प्रकार

घटनाकब चलती है
annotation.createdकोई एनोटेटर किसी instance के लिए लेबल जमा करता है
annotation.updatedकोई एनोटेटर पहले जमा किया गया लेबल बदलता है
item.fully_annotatedकोई instance अपनी ज़रूरी एनोटेशन ओवरलैप संख्या तक पहुँच जाता है
task.completedकाम के सारे instance पूरी तरह एनोटेट हो जाते हैं
user.phase_completedकोई एनोटेटर एक चरण पूरा करता है (Solo Mode कार्यप्रवाह)
quality.attention_check_failedकोई एनोटेटर ध्यान जाँच में विफल होता है
webhook.testपरीक्षण के लिए एडमिन API से हाथ से चलाई जाती है

सारी मौजूदा और आगे आने वाली घटनाओं की सदस्यता के लिए "*" इस्तेमाल करें।

Payload फ़ॉर्मैट

सारी घटनाओं का लिफ़ाफ़ा एक जैसा होता है:

json
{
  "event_id": "evt_01HXYZ...",
  "event_type": "annotation.created",
  "timestamp": "2026-03-17T14:23:01Z",
  "task_name": "sentiment-study",
  "data": {
    ...
  }
}

annotation.created payload

json
{
  "event_type": "annotation.created",
  "data": {
    "annotator_id": "user123",
    "instance_id": "doc_042",
    "annotation": {
      "sentiment": "positive",
      "confidence": "high"
    },
    "submitted_at": "2026-03-17T14:23:01Z"
  }
}

item.fully_annotated payload

json
{
  "event_type": "item.fully_annotated",
  "data": {
    "instance_id": "doc_042",
    "annotator_count": 3,
    "annotations": [
      {"annotator_id": "user1", "sentiment": "positive"},
      {"annotator_id": "user2", "sentiment": "positive"},
      {"annotator_id": "user3", "sentiment": "neutral"}
    ]
  }
}

task.completed payload

json
{
  "event_type": "task.completed",
  "data": {
    "task_name": "sentiment-study",
    "total_instances": 500,
    "total_annotations": 1500,
    "completed_at": "2026-03-17T15:00:00Z"
  }
}

हस्ताक्षर सत्यापित करना

जब secret कॉन्फ़िगर किया गया हो, तो Potato हर अनुरोध पर Standard Webhooks (HMAC-SHA256) से हस्ताक्षर करता है। इसमें तीन हेडर शामिल होते हैं:

हेडरमान
webhook-idविशिष्ट डिलीवरी ID
webhook-timestampडिलीवरी का Unix टाइमस्टैम्प
webhook-signatureHMAC-SHA256 हस्ताक्षर

Python सत्यापन

python
import hmac
import hashlib
import time
 
def verify_webhook(payload_bytes: bytes, headers: dict, secret: str) -> bool:
    webhook_id = headers.get("webhook-id", "")
    timestamp = headers.get("webhook-timestamp", "")
    signature = headers.get("webhook-signature", "")
 
    # Reject stale requests (older than 5 minutes)
    if abs(time.time() - int(timestamp)) > 300:
        return False
 
    signed_content = f"{webhook_id}.{timestamp}.{payload_bytes.decode()}"
    expected = hmac.new(
        secret.encode(),
        signed_content.encode(),
        hashlib.sha256
    ).hexdigest()
 
    return hmac.compare_digest(f"v1,{expected}", signature)

Node.js सत्यापन

javascript
const crypto = require('crypto');
 
function verifyWebhook(payload, headers, secret) {
  const webhookId = headers['webhook-id'];
  const timestamp = headers['webhook-timestamp'];
  const signature = headers['webhook-signature'];
 
  // Reject stale requests
  if (Math.abs(Date.now() / 1000 - parseInt(timestamp)) > 300) {
    return false;
  }
 
  const signedContent = `${webhookId}.${timestamp}.${payload}`;
  const expected = crypto
    .createHmac('sha256', secret)
    .update(signedContent)
    .digest('hex');
 
  return crypto.timingSafeEqual(
    Buffer.from(`v1,${expected}`),
    Buffer.from(signature)
  );
}

रीट्राई का व्यवहार

विफल डिलीवरी (2xx के अलावा कोई उत्तर या टाइमआउट) अपने आप दोबारा आज़माई जाती हैं:

प्रयासदेरी
1 (पहला)तुरंत
25 सेकंड
330 सेकंड
45 मिनट
530 मिनट
61 घंटा

6 विफल प्रयासों के बाद डिलीवरी को स्थायी रूप से विफल चिह्नित कर दिया जाता है। रीट्राई क़तार {output_dir}/.webhooks/webhook_retries.db पर SQLite में सहेजी जाती है — बचे हुए रीट्राई सर्वर के दोबारा शुरू होने पर भी बने रहते हैं।

मॉनिटरिंग और परीक्षण

एडमिन API

Webhook की स्थिति और आँकड़े देखें:

bash
# List all webhooks and their delivery statistics
curl -H "X-API-Key: $ADMIN_API_KEY" \
  http://localhost:8000/admin/api/webhooks

उत्तर:

json
{
  "endpoints": [
    {
      "name": "my-pipeline",
      "url": "https://...",
      "events": ["annotation.created"],
      "active": true,
      "stats": {
        "total_emitted": 1240,
        "total_failed": 3,
        "pending_retries": 0,
        "last_success": "2026-03-17T14:23:01Z"
      }
    }
  ]
}

परीक्षण webhook भेजें

bash
curl -X POST -H "X-API-Key: $ADMIN_API_KEY" \
  http://localhost:8000/admin/api/webhooks/test \
  -H "Content-Type: application/json" \
  -d '{"endpoint_name": "my-pipeline"}'

इससे बताए गए एंडपॉइंट पर तुरंत एक webhook.test घटना चलती है।

पूरा कॉन्फ़िगरेशन संदर्भ

yaml
webhooks:
  enabled: true
  endpoints:
    - name: string           # unique name for this endpoint
      url: string            # HTTPS URL to POST to
      secret: string         # optional HMAC secret for signature verification
      events:                # list of event types, or ["*"] for all
        - annotation.created
      active: true           # set false to disable without removing
      timeout: 10            # request timeout in seconds (default: 10)
      max_retries: 6         # max retry attempts (default: 6)

आगे पढ़ें

कार्यान्वयन के विवरण के लिए स्रोत दस्तावेज़ देखें।