MCPcopy
hub / github.com/IBM/AssetOpsBench / next_wonum

Method next_wonum

src/servers/wo/couch.py:102–118  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)")

Callers 1

create_workorderFunction · 0.45

Calls 3

getMethod · 0.95
putMethod · 0.95
CouchErrorClass · 0.85

Tested by

no test coverage detected