releaser ee39fa06b0
Unbound Release / Check Preconditions (push) Successful in 26s
Unbound Release / Create Tag (push) Skipped
subscriptions / coverage-baseline (push) Successful in 59s
Unbound Release / Generate Changelog and Handle PR (push) Successful in 29s
subscriptions / test (push) Skipped
subscriptions / vulnerabilities (push) Skipped
pre-commit / pre-commit (push) Skipped
Unbound Release / Create Release (push) Successful in 30s
Release / release (push) Successful in 4m0s
chore(release): prepare for v0.1.1 (#17)
## [0.1.1] - 2026-08-21

### 🐛 Bug Fixes

- *(deps)* Update module github.com/stretchr/testify to v1.12.0 (#12)
- *(deps)* Update module github.com/stretchr/testify to v1.12.1 (#14)

### ⚙️ Miscellaneous Tasks

- *(deps)* Update actions/checkout action to v7 (#2)
- *(deps)* Update actions/cache action to v6 (#4)
- *(deps)* Update pre-commit hook alessandrojcm/commitlint-pre-commit-hook to v9.26.0 (#6)
- *(deps)* Update actions/setup-go action to v7 (#8)
- *(deps)* Update actions/setup-python action to v7 (#10)
- *(deps)* Update pre-commit hook golangci/golangci-lint to v2.13.1 (#15)

<!-- generated by git-cliff -->

---

**Note:** Please use **Squash Merge** when merging this PR.

Reviewed-on: #17
Co-authored-by: Unbound Releaser <releaser@unbound.se>
2026-08-29 11:27:52 +00:00

subscriptions

Shared core for Shiny's cross-service read-your-writes GraphQL subscriptions (ADR-0009 tier-3, ADR-0012).

An entity shown in the UI is frequently projected from another service's event, so the owning service exposes a GraphQL subscription, drives it from a per-replica transient AMQP consumer, and pushes a lightweight poke once the change is visible in its own read view — the client then refetches the authoritative query. This package is the reusable, type-generic, hardened core of that pattern, extracted from the hand-rolled copies in authz-service (availableCompanies) and accounting-service (entryBasesChanged).

import "gitea.unbound.se/shiny/subscriptions"

// One registry per subscription, parameterised by the GraphQL payload type.
reg := subscriptions.New[model.EntryBasisChange](subscriptions.WithLogger(logger))

// Resolver: register a websocket consumer (key by company, user, …).
ch, cleanup, _ := reg.AddReceiver(companyID)
go func() { <-ctx.Done(); cleanup() }()
return ch, nil

// AMQP handler: gate the push on the read view, off the delivery goroutine.
reg.Submit(ev.CompanyID, func(ctx context.Context) (*model.EntryBasisChange, bool) {
    basis, err := readView.FindEntryBasisById(ctx, id)
    if err != nil {
        return nil, false // transient read error — keep waiting
    }
    return &model.EntryBasisChange{ID: id, Removed: removed}, removed == (basis == nil)
})

What the registry owns (so services don't re-roll it): the keyed subscriber map, non-blocking buffered fan-out (sends under the read lock so a close can't race a send), a bounded worker pool that runs the read-view gate off the AMQP delivery goroutine, and the retry/timeout budget. What stays in the service: the event→(key, payload) mapping and the Producer read-view closure.

The poke is idempotent and drop-tolerant — the client refetches on any poke — so the worker acks immediately and a dropped/duplicated poke self-heals. Wire an Observer to surface dropped/skipped pushes as metrics.

S
Description
Shared core for cross-service read-your-writes GraphQL subscriptions (ADR-0012)
Readme
69 KiB
v0.1.1
Latest
2026-08-29 11:36:59 +00:00
Languages
Go 100%