Allocate the next WONUM for a site from a counter doc. Reproducible across a benchmark run because allocation is sequential and seeded by `reset`. For fully fixed ids, callers may pass an explicit wonum to create_workorder instead.
(self, site_id: str)
| 100 | |
| 101 | # ---- deterministic WO number allocation ---- |
| 102 | async def next_wonum(self, site_id: str) -> str: |
| 103 | """Allocate the next WONUM for a site from a counter doc. |
| 104 | |
| 105 | Reproducible across a benchmark run because allocation is sequential and |
| 106 | seeded by `reset`. For fully fixed ids, callers may pass an explicit wonum |
| 107 | to create_workorder instead. |
| 108 | """ |
| 109 | cid = f"counter:{site_id.upper()}" |
| 110 | for _ in range(5): # retry on write conflict |
| 111 | doc = await self.get(cid) or {"_id": cid, "type": "counter", "value": 1000} |
| 112 | doc["value"] = int(doc["value"]) + 1 |
| 113 | try: |
| 114 | await self.put(doc) |
| 115 | return str(doc["value"]) |
| 116 | except CouchError: |
| 117 | continue |
| 118 | raise CouchError("could not allocate wonum (counter contention)") |
no test coverage detected