FossilRepo

fossilrepo / fossil / agent_claims.py
Blame History Raw 44 lines
1
"""Agent ticket claim tracking for exclusive work assignment.
2
3
When multiple agents are working on a repository, they need a way to atomically
4
claim tickets so two agents don't work on the same issue simultaneously.
5
Claims are Django-side since Fossil tickets live in SQLite.
6
"""
7
8
from django.db import models
9
10
from core.models import ActiveManager, Tracking
11
12
13
class TicketClaim(Tracking):
14
"""Tracks which agent has claimed a Fossil ticket for exclusive work."""
15
16
class Status(models.TextChoices):
17
CLAIMED = "claimed", "Claimed"
18
SUBMITTED = "submitted", "Submitted"
19
MERGED = "merged", "Merged"
20
RELEASED = "released", "Released"
21
22
repository = models.ForeignKey("fossil.FossilRepository", on_delete=models.CASCADE, related_name="ticket_claims")
23
ticket_uuid = models.CharField(max_length=64)
24
agent_id = models.CharField(max_length=200)
25
workspace = models.ForeignKey("fossil.AgentWorkspace", null=True, blank=True, on_delete=models.SET_NULL, related_name="claims")
26
claimed_at = models.DateTimeField(auto_now_add=True)
27
released_at = models.DateTimeField(null=True, blank=True)
28
status = models.CharField(max_length=20, choices=Status.choices, default=Status.CLAIMED)
29
summary = models.TextField(blank=True, default="", help_text="Work summary when submitted")
30
files_changed = models.JSONField(default=list, blank=True, help_text="List of files changed")
31
32
objects = ActiveManager()
33
all_objects = models.Manager()
34
35
class Meta:
36
# Uniqueness for active claims is enforced at the application level
37
# using select_for_update in the claim endpoint. We cannot use
38
# unique_together because soft-deleted rows would violate the
39
# constraint when the ticket is reclaimed.
40
ordering = ["-claimed_at"]
41
42
def __str__(self):
43
return f"{self.ticket_uuid[:12]} claimed by {self.agent_id}"
44

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button