Complete worked example
python
from hashlib import sha256
def inspect_example(outcomes, maximum, raw):
if type(maximum) is not int or maximum <= 0 or not outcomes:
raise ValueError('positive budget and scripted outcomes required')
batch_key = sha256(raw.encode('utf-8')).hexdigest()
keys, delays, seen = [], [], []
status = 'failed'
for attempt in range(maximum):
kind = outcomes[min(attempt, len(outcomes)-1)]
keys.append(batch_key)
seen.append(kind)
if kind == 'success':
status = 'committed'
break
if kind != 'transient':
break
if attempt + 1 < maximum:
delays.append(2 ** attempt)
return {'attempts':len(keys),'status':status,'sameBatchKey':len(set(keys)) == 1,
'sourceBytes':len(raw.encode('utf-8')),'delays':delays}- Reasoning
- A scripted adapter supplies outcomes from the fixture. Each attempted operation records the stable key, then success stops with a committed status, permanent failure stops immediately, and transient failure schedules another attempt only if budget remains. Planned delays grow as powers of two between attempts.