{"modulePath":"github.com/uber/submitqueue","version":"v0.3.0-20261125210437-add1a4bd2ea2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package hook\n\nPackage hook holds the domain-neutral mechanics of the hooks framework: the controller that turns hook events on a queue into hook.Hook calls, the reconciler for the events that never made it, and the helper a producer publishes an event through.\n\nThe controller is domain-neutral. Each domain runs its own hook topic and its own instance of this stage — \"per-domain\" is about the topic and the wiring, not about the logic, which is the same everywhere: decode, validate, resolve, invoke. The domain-specific parts are the topic name the host maps the key to and the hooks its resolver returns.\n\nThe contract this stage consumes is api/base/hook; the hooks it invokes implement platform/extension/hook.\n\n## Functions\n\n```go\nfunc Publish(\n\tctx context.Context,\n\tregistry consumer.TopicRegistry,\n\ttenant string,\n\tevent *basehook.HookEvent,\n\tpartitionKey string,\n) error\n```\nPublish sends one hook event to the domain's hook topic for tenant, partitioned by partitionKey. The topic key is not a parameter: a domain runs a single hook topic, and the caller's registry binds that key to a wire topic.\n\nThe event id is the message id, so a redelivery republishing the same event dedups into the original message instead of enqueuing a second one. Callers pass the partition key their own topic partitions on, carrying that ordering across the seam.\n\nErrors are returned unclassified, leaving retryability to the caller's classifier: a malformed event is the caller's bug, not a transient fault.\n\n## Types\n\n```go\ntype Controller struct {\n\t// contains filtered or unexported fields\n}\n```\nController consumes hook events and runs the hooks each one resolves to.\n\n```go\nfunc NewController(\n\tlogger *zap.SugaredLogger,\n\tscope tally.Scope,\n\thooks hookext.Hooks,\n\ttopicKey consumer.TopicKey,\n\tconsumerGroup string,\n) *Controller\n```\nNewController builds the hook controller for a host. A host registers the stage even when it has no integrations yet — a resolver that returns no hooks still acks, so \"off\" and \"lost\" stay distinguishable.\n\n```go\nfunc (c *Controller) ConsumerGroup() string\n```\nConsumerGroup returns the consumer group for offset tracking.\n\n```go\nfunc (c *Controller) Name() string\n```\nName returns the controller name for logging and metrics.\n\n```go\nfunc (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) error\n```\nProcess decodes the delivery's hook event, validates it, and runs every hook the resolver returns for it. Returns nil to ack, or an error to nack (retry) / reject (DLQ).\n\nAn ack means \"no hook still has work to do with this event\", not \"something acted on it\": a hook that does not care returns nil, and an event no hook resolves to is acked unhandled.\n\n```go\nfunc (c *Controller) TopicKey() consumer.TopicKey\n```\nTopicKey returns the topic key this controller subscribes to.\n\n```go\ntype DLQController struct {\n\t// contains filtered or unexported fields\n}\n```\nDLQController is the reconciler for the hook topic's dead-letter queue. Implements consumer.Controller.\n\nIt reconciles nothing, because there is nothing it may touch: a hook never writes pipeline state, so a hook event that could not be delivered leaves no half-finished transition behind. What is lost is the side effect — a comment not posted, a row not exported — which only a person can decide how to recover. So this controller makes the loss impossible to miss and hands it over: it records the complete event and why it failed, counts it on a metric meant to page, and acks so the event does not sit in the DLQ unnoticed. Republishing the logged event recovers it.\n\nThat is a deliberate step up from the log topic's DLQ, which warns and moves on. Dropping an observability row costs a gap in a read model; dropping a land-failure comment costs a support ticket, and nothing else in the system will notice it is missing.\n\n```go\nfunc NewDLQController(\n\tlogger *zap.SugaredLogger,\n\tscope tally.Scope,\n\ttopicKey consumer.TopicKey,\n\tconsumerGroup string,\n) *DLQController\n```\nNewDLQController builds the DLQ reconciler for a host's hook topic. topicKey is the dead-letter key (the hook topic key plus the queue's DLQ suffix), not the primary one.\n\n```go\nfunc (c *DLQController) ConsumerGroup() string\n```\nConsumerGroup returns the consumer group for offset tracking.\n\n```go\nfunc (c *DLQController) Name() string\n```\nName returns the controller name for logging and metrics.\n\n```go\nfunc (c *DLQController) Process(_ context.Context, delivery consumer.Delivery) error\n```\nProcess records a dropped hook event and acks it.\n\nIt never returns an error: a failure here would re-deliver the message forever, since the DLQ consumer has no DLQ of its own and treats everything as retryable. The record is the outcome, so the only way to fail is not to write one.\n\n```go\nfunc (c *DLQController) TopicKey() consumer.TopicKey\n```\nTopicKey returns the topic key this controller subscribes to.\n\n","path":"github.com/uber/submitqueue/platform/hook","name":"hook","synopsis":"Package hook holds the domain-neutral mechanics of the hooks framework: the controller that turns hook events on a queue into hook.Hook calls, the reconciler for the events that never made it, and the helper a producer publishes an event through.","isRedistributable":true}
