auditqueue

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package auditqueue provides a bounded, asynchronous worker pool for audit work. Both the Valkey rate-store round-trip and the audit.Logger HTTP POST are blocking network calls that must never run on the Check() hot path, so they are submitted here as jobs and executed on worker goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job func(ctx context.Context)

Job is a unit of audit work executed on a worker goroutine. It receives a background context not tied to the (already-returned) request.

type Options

type Options struct {
	// Metrics records dropped jobs and queue depth. May be nil.
	Metrics *metric.Metrics

	// Size bounds the number of buffered jobs. Values < 1 default to 1.
	Size int

	// Workers is the number of draining goroutines. Values < 1 default to 1.
	Workers int

	// DispatchTimeout bounds how long a single job may run before its context
	// is cancelled. Values <= 0 default to defaultDispatchTimeout.
	DispatchTimeout time.Duration
}

Options configures a Queue.

type Queue

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

Queue is a bounded async worker pool.

func New

func New(opts Options) *Queue

New creates a Queue. Call Start before submitting and Close on shutdown.

func (*Queue) Close

func (q *Queue) Close() error

Close stops accepting new jobs and drains those already queued before returning. It is safe to call more than once.

func (*Queue) Start

func (q *Queue) Start()

Start launches the worker goroutines that drain the queue.

func (*Queue) Submit

func (q *Queue) Submit(ctx context.Context, job Job) bool

Submit schedules a job for asynchronous execution. It never blocks: if the pool is saturated the job is dropped and counted. It returns false when the job was dropped.

Jump to

Keyboard shortcuts

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