> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/pattern-workflow-worker.md).

# पैटर्न: वर्कफ़्लो वर्कर

Python SDK पैटर्न: Agent स्टेज में टास्क लेबल करने वाली सेवा चलाएँ, या शेड्यूल पर किसी स्टेज के टास्क प्रोसेस करने वाला polling worker बनाएँ।

अपने कोड से टास्क पर काम करवाने के दो तरीके हैं।

| तरीका          | टास्क आप तक कैसे पहुँचते हैं                      | कब इस्तेमाल करें                                          |
| -------------- | ------------------------------------------------- | --------------------------------------------------------- |
| Agent स्टेज    | Unitlab हर टास्क के लिए साइन किया वेबहुक भेजता है | आपका मॉडल HTTPS सेवा के रूप में चलता है। कोई पोलिंग नहीं। |
| Polling worker | आपका job किसी स्टेज के टास्क सूचीबद्ध करता है     | बैच job या शेड्यूल की गई स्क्रिप्ट                        |

## Agent स्टेज <a href="#agent-stage" id="agent-stage"></a>

ऐप में वर्कफ़्लो में एक Agent स्टेज जोड़ें और उसे अपनी सेवा की ओर सेट करें। सेवा इवेंट को वेरिफ़ाई करती है, टास्क लेबल करती है और रन पूरा करती है। देखें [टास्क एनोटेशन और Agent वेबहुक](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/task-annotations-and-agent-webhooks.md)।

## Polling worker <a href="#polling-worker" id="polling-worker"></a>

```python
from unitlab import UnitlabClient, ValidationError

client = UnitlabClient()
project = client.projects.get("PROJECT_ID")
stage = project.workflow.get_stage(name="Auto QA")

for task in stage.get_tasks():
    try:
        task.claim()
    except ValidationError:
        continue                     # someone else took it
    if passes_checks(task):
        task.submit()
    else:
        task.release()
client.close()
```

* कोई कार्रवाई करने से पहले claim करें, ताकि दो worker कभी एक ही टास्क न संभालें।
* हर रन छोटा और idempotent रखें; अगला रन बचा हुआ काम उठा लेता है।
* टास्क ID और एक्शन लॉग करें, मीडिया या साइन किए गए लिंक नहीं।

## संबंधित पेज <a href="#related" id="related"></a>

[वर्कफ़्लो स्टेज और टास्क](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/workflow-stages-and-tasks.md) · [बल्क वर्कफ़्लो ऑपरेशन](https://docs.unitlab.ai/api-sdk-cli/hi/sdks/bulk-workflow-operations.md) · [Agent स्टेज](https://docs.unitlab.ai/documentation/hi/workflows/agent-stage)
