publisher

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: BSD-2-Clause Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package publisher emits typed task change events onto the vault's task topic. It is the producer half of the CQRS pair whose consumer is agent-task-executor's compacted task view: one record per task id, and a tombstone on delete.

The interface is deliberately caller-agnostic. Every mutation path in vault-api hands a task to it — the typed write handlers, and the pull path that detects externally pushed changes — so that exactly one process writes git and exactly one stream feeds every consumer.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = stderrors.New("task publisher not ready")

ErrNotReady is returned by a Deferred publisher whose underlying publisher has not been built yet. It reports a transient startup state rather than a failure: a caller logs it and the next publish after construction succeeds.

Functions

func IsPermanent added in v0.7.0

func IsPermanent(err error) bool

IsPermanent reports whether a publish error can never succeed on retry because the broker rejected the message itself rather than the connection.

The distinction is load-bearing for the pull path: a caller that retries transient failures forever needs to know which failures are not transient, and the alternative — counting every failure toward an abandonment cap — drops real changes during any outage longer than a few ticks.

Types

type Deferred added in v0.8.0

type Deferred struct {
	// contains filtered or unexported fields
}

Deferred is a TaskPublisher that stands in for one built later.

The Kafka producer must not be built on the startup path. NewSyncProducer blocks while a broker is unreachable, so constructing it before the HTTP server starts would make vault-api's read endpoints depend on Kafka being up — and a write endpoint that built it on first use would hang that request instead. Run therefore hands out a Deferred immediately and builds the real publisher in the background; until construction finishes, publishes report ErrNotReady rather than blocking.

A publish that misses this window is not lost: the write itself has already landed in git, and the pull path republishes the same change from the commit diff, so the stream converges without the caller.

func NewDeferred added in v0.8.0

func NewDeferred() *Deferred

NewDeferred creates a Deferred with no publisher installed. Every publish reports ErrNotReady until Set is called.

It returns the concrete type rather than TaskPublisher on purpose: Set and Ready exist only on the handle, and a caller holding the interface could not install the publisher it is meant to stand in for. Callers that only publish take it as a TaskPublisher.

func (*Deferred) PublishChanged added in v0.8.0

func (d *Deferred) PublishChanged(ctx context.Context, task lib.Task) error

PublishChanged delegates to the installed publisher, or reports ErrNotReady.

func (*Deferred) PublishDeleted added in v0.8.0

func (d *Deferred) PublishDeleted(ctx context.Context, id lib.TaskIdentifier) error

PublishDeleted delegates to the installed publisher, or reports ErrNotReady.

func (*Deferred) Ready added in v0.8.0

func (d *Deferred) Ready() bool

Ready reports whether Set has been called.

func (*Deferred) Set added in v0.8.0

func (d *Deferred) Set(p TaskPublisher)

Set installs the built publisher. Publishes issued after this call use it.

A nil publisher is ignored rather than stored: storing it would put a non-nil pointer to a nil interface in the holder, so Ready would report true and the next publish would call a method on a nil interface and panic on the request path. Leaving the handle not-ready is the honest reading of "nothing installed".

type TaskPublisher

type TaskPublisher interface {
	// PublishChanged publishes an upsert event for the given task.
	PublishChanged(ctx context.Context, task lib.Task) error
	// PublishDeleted publishes a tombstone for the given task identifier.
	PublishDeleted(ctx context.Context, id lib.TaskIdentifier) error
}

TaskPublisher publishes task change and deletion events to Kafka.

func NewDiscard added in v0.8.0

func NewDiscard() TaskPublisher

NewDiscard returns a TaskPublisher that publishes nothing and reports success.

It is what a Deferred holds when change events are switched off by configuration. The write path calls the interface unconditionally, so without it a deliberately disabled producer would take the not-ready branch and log an error on every successful write — noise that reads as a fault and can trip error-rate alerting.

func NewKafkaTaskPublisher

func NewKafkaTaskPublisher(
	ctx context.Context,
	brokers string,
	topicPrefix base.TopicPrefix,
	currentDateTimeGetter libtime.CurrentDateTimeGetter,
) (TaskPublisher, func() error, error)

NewKafkaTaskPublisher builds a TaskPublisher over a Kafka sync producer using lib.TaskV1SchemaID, so the topic name is derived from the schema rather than assembled here. The returned closer releases the producer and must be called when the publisher is no longer needed.

The producer-creation error path is deliberately not unit-tested: sarama blocks on an unreachable broker rather than failing fast, so a spec that passes a bogus broker string hangs instead of asserting. Covering it would need an injected producer-constructor seam that no caller needs yet; the path is exercised at deployment, where a bad broker string fails the process at startup.

func NewTaskPublisher

func NewTaskPublisher(
	eventObjectSender cdb.EventObjectSender,
	schemaID cdb.SchemaID,
	currentDateTimeGetter libtime.CurrentDateTimeGetter,
) TaskPublisher

NewTaskPublisher creates a TaskPublisher that sends events via EventObjectSender.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL