elsa-workflows / elsa-workflows/elsa-extensions
Implement IWorkflowDefinitionStore.TryUpdateLatestAsync (CAS) for Mongo/Dapper/Elasticsearch
- Dominant language
- C#
- Stars
- 49
- Forks
- 48
- Avg merge
- 21h 35m
- Merged PRs (30d)
- 20
Description
## Background
elsa-core#8092 (Fixes elsa-workflows/elsa-core#8064 / BPMN W29) adds `IWorkflowDefinitionStore.TryUpdateLatestAsync` — a compare-and-swap used by `PUT bpmn/definitions/{id}/document` so If-Match + save are atomic (lost race → 412). Metadata carried into the document edit is read inside the same CAS.
Memory and EF Core implement the method in elsa-core. Caching decorator forwards it.
## Gap
Persistence providers in this repo (MongoDB, Dapper, Elasticsearch — and EventSourcing if applicable) implement `IWorkflowDefinitionStore` but do not yet have `TryUpdateLatestAsync`. Until they do, BPMN document PUT is not concurrency-safe on those stores.
## Ask
Implement `TryUpdateLatestAsync` with the same contract as elsa-core:
- Load matching latest definition
- `matchesExpected` gate (ETag / content hash / snapshot fields)
- Apply `update` on the just-loaded row
- Persist atomically (provider-appropriate: conditional update / transaction / expected version in WHERE)
- Return conflict when zero rows updated (caller maps to 412)
Keep the surface narrow — no distributed lock. Mirror EF/Memory semantics; don’t invent a different API.
## References
- elsa-core PR: https://github.com/elsa-workflows/elsa-core/pull/8092
- Issue: https://github.com/elsa-workflows/elsa-core/issues/8064
- Architect: CAS preferred over a shared lock; extensions follow-up called out as non-blocking for the core PR.
## Acceptance
- Mongo, Dapper, and Elasticsearch stores implement `TryUpdateLatestAsync`
- Unit/integration coverage for conflict vs success paths where practical
- Document PUT against those stores returns 412 on a lost race (or equivalent test with store doubles)
Do not block merging elsa-core#8092 on this issue.
Contributor guide
Research direction
Start by reading the elsa-core TryUpdateLatestAsync contract and the existing MongoDB, Dapper, and Elasticsearch implementations of IWorkflowDefinitionStore. Compare their persistence and versioning behavior, then add conflict and success coverage where practical. Done means all three stores implement the CAS method and document PUT reports 412 for a lost race.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, elasticsearch, mongodb
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100