Repository navigation
feat(durable): key_scope: lets runs of different workflows share a key - #53
Merged
Merged
Conversation
A workflow that names a `key_scope:` shares its keys with every workflow that names the same scope: one run per scope and key holds it, so an index update and an index rebuild for one account never run at once. A start that finds another workflow's run holding the key, or waiting on it, joins the end of the line whatever its `on_duplicate:` says. `on_duplicate:` and `debounce:` only meet the start's own workflow's runs. A scoped workflow must use `reuse: :after_close`. The start's key lock, the holder unique index and the kept-lock check in the claim query all cover the scope. Migration 20261125000000 adds a nullable `key_scope` column and a unique index; no row is rewritten and the per-workflow index stays for nodes not yet upgraded. Closes #52.
…rder A scoped run being rolled back keeps its key until its undo has run, and a start of any workflow in the scope, its own included, waits behind it: the compensations write what the next run works on. A run of the line that comes for the key after the run it waited behind was cancelled out of the line waits behind the newest run started before it (`Keys.ahead/2`), so the line stays in start order. `Query.list_keys/1` and `count_keys/1` give each workflow's row the scope's holder (`holder_workflow_name`, `key_scope`), so the `holder_status:` filter agrees with it, and `get_execution/2` returns `key_scope`. The dashboard's Keys page and a run's Key view show the scope's holder and runs.
The dashboard gets durable's .credo.exs, credo in its dev/test deps, a Credo step in CI and `credo --strict` in `mix precommit`. Its 28 findings are fixed: alias order, nested module aliases, string sigils, one filter instead of three, case over a one-clause cond, and the nesting and complexity ones split into helpers (status text and tones are lookup tables now).
Both .credo.exs files add ExSlop.recommended_checks() to the enabled list, so `credo --strict` (CI and `mix precommit`) runs them. LengthComparison skips test/: a test asserts the exact size of a list it built, and the check is for code that runs. Fixed what they found: Map.new over a reduce of Map.put, a length/1 guard and comparisons made pattern matches (Enum.count_until/2 for the 100-run threshold), an identity Enum.map, two docs that restated their names, and atom-or-string key reads of maps that are always read back from JSONB with string keys. Durable's rollback_interrupted activity reads its error as stored, since storable_error/1 can hand atom keys.
The check was that the new deadline sat 0..30 ms from when the test read it, so a retry that took longer than 30 ms on a loaded machine failed it. It's now between the clock read just before the retry and just after, plus the lane's 30 ms, which doesn't depend on how long the retry took. A retry that gave the lane twice its time still fails it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52.
A workflow that names
key_scope: "account_index"shares its keys with every workflow naming the same scope. One run per scope and key holds it, so an index update and a rebuild for one account never run at the same time. Workflows withoutkey_scope:keep their own keys, even two in one module, so nothing changes for existing users.Four commits: the feature, its follow-ups, credo for the dashboard, and ex_slop for both packages.
Rules
on_duplicate:says. It never gets that run's id back, cancels it, sends it an event or gives it its input.on_duplicate:anddebounce:meet only the start's own workflow's runs. Each workflow has at most one run waiting in the line.reuse: :after_close; anything else fails the compile.key_scope:passed toDurable.start/3raises, asreuse:does.What changed
20261125000000key_scopecolumn and a unique index on(key_scope, key) WHERE holds_key AND key_scope IS NOT NULL. No row is rewritten; the per-workflow holder index stays for nodes not yet upgraded.Keys.lock_name/1Keysundoing?/2), sends the start to the line (behind_others/4). A run that has to wait again waits behind the newest run started before it (ahead/2).Executor.without_key/2reuse: :neveralready did).Query.list_keys/1,count_keys/1holder_workflow_nameandkey_scope; theholder_status:filter agrees with it.get_execution/2returnskey_scope.DESIGN.mdupdated first.guides/workflow_keys.mdkey_scope:section; DSL option docs;ARCHITECTURE.mdkeys paragraph, rules 3, 16 and 30.Tests
key_scope_test.exs(31 tests). Starts in each direction wait for each other. The line runs in start order, including after a cancel. Eachon_duplicate:mode waits its turn. A rollback keeps the key:cancel(rollback: true).Also the scope-aware listings, a scope change, unscoped workflows staying separate, and the DSL refusals.
integration/issue52_test.exs, on live pollers:Dashboard
keys_live_test.exs: the Key view and the Keys page for a shared key.Every new test was written first and failed on the code before its fix. I also removed each piece on its own and checked that a test fails:
without_key/2keeping the keyundoing?/2Tooling (separate commits)
.credo.exs, the dev/test dep,credo --strictinmix precommitand a Credo step in CI. Its 28 findings are fixed.ExSlop.recommended_checks()(28 checks) is the tail of eachenabled:list, so it runs undercredo --strictlocally and in CI.LengthComparisonskipstest/: those assertions check the exact size of lists the test built. All other findings are fixed.Verified (final code)
--strict+ ex_slopcompile --warnings-as-errorsNot changed
Durable.rollback/2, oron_failure: [rollback_after: ms]), its undo runs beside whichever run holds the key then. I checked this with a run; the guide says so. Fixing it would mean an undo that waits in line for the key.Durable.Stats.keys/1still counts per workflow.