pipeline

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pipeline provides async pipeline for separating scan and upload.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pipeline

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

Pipeline manages async upload of scan results. This allows scans to complete immediately while uploads happen in background.

func NewPipeline

func NewPipeline(config *PipelineConfig, uploader Uploader) *Pipeline

NewPipeline creates a new upload pipeline.

func (*Pipeline) Flush

func (p *Pipeline) Flush(ctx context.Context) error

Flush blocks until the queue is empty.

func (*Pipeline) GetStats

func (p *Pipeline) GetStats() *Stats

GetStats returns current pipeline statistics.

func (*Pipeline) QueueLength

func (p *Pipeline) QueueLength() int

QueueLength returns the current queue length.

func (*Pipeline) Start

func (p *Pipeline) Start(ctx context.Context) error

Start begins the upload workers.

func (*Pipeline) Stop

func (p *Pipeline) Stop(ctx context.Context) error

Stop gracefully stops the pipeline. Waits for in-progress uploads to complete.

func (*Pipeline) Submit

func (p *Pipeline) Submit(report *ctis.Report, opts ...SubmitOption) (string, error)

Submit queues a report for async upload. Returns immediately after queueing.

type PipelineConfig

type PipelineConfig struct {
	// QueueSize is the maximum number of pending uploads.
	// Default: 1000
	QueueSize int

	// Workers is the number of concurrent upload workers.
	// Default: 3
	Workers int

	// RetryAttempts is the number of retry attempts for failed uploads.
	// Default: 3
	RetryAttempts int

	// RetryDelay is the base delay between retries.
	// Default: 5 seconds (exponential backoff applied)
	RetryDelay time.Duration

	// UploadTimeout is the timeout for each upload attempt.
	// Default: 2 minutes
	UploadTimeout time.Duration

	// OnSubmitted is called when a report is queued.
	OnSubmitted func(item *QueueItem)

	// OnCompleted is called when an upload completes.
	OnCompleted func(item *QueueItem, result *Result)

	// OnFailed is called when an upload fails after all retries.
	OnFailed func(item *QueueItem, err error)

	// Verbose enables debug logging.
	Verbose bool
}

PipelineConfig configures the upload pipeline.

func DefaultPipelineConfig

func DefaultPipelineConfig() *PipelineConfig

DefaultPipelineConfig returns sensible defaults.

type QueueItem

type QueueItem struct {
	ID          string       `json:"id"`
	Report      *ctis.Report `json:"-"` // Not serialized
	ReportJSON  []byte       `json:"report_json,omitempty"`
	JobID       string       `json:"job_id,omitempty"`
	TenantID    string       `json:"tenant_id,omitempty"`
	ToolName    string       `json:"tool_name"`
	SubmittedAt time.Time    `json:"submitted_at"`
	Attempts    int          `json:"attempts"`
	LastError   string       `json:"last_error,omitempty"`
	Priority    int          `json:"priority"` // Higher = more urgent
}

QueueItem represents a pending upload.

type Result

type Result struct {
	ID              string    `json:"id"`
	ReportID        string    `json:"report_id"`
	Status          string    `json:"status"` // pending, uploading, completed, failed
	FindingsCreated int       `json:"findings_created"`
	AssetsCreated   int       `json:"assets_created"`
	Error           string    `json:"error,omitempty"`
	SubmittedAt     time.Time `json:"submitted_at"`
	CompletedAt     time.Time `json:"completed_at,omitempty"`
	DurationMs      int64     `json:"duration_ms,omitempty"`
}

Result represents an upload result.

type Stats

type Stats struct {
	Submitted   int64 `json:"submitted"`
	Completed   int64 `json:"completed"`
	Failed      int64 `json:"failed"`
	InProgress  int   `json:"in_progress"`
	QueueLength int   `json:"queue_length"`
	TotalBytes  int64 `json:"total_bytes"`
}

Stats returns pipeline statistics.

type SubmitOption

type SubmitOption func(*QueueItem)

SubmitOption is an option for Submit.

func WithJobID

func WithJobID(jobID string) SubmitOption

WithJobID sets the job ID for tracking.

func WithPriority

func WithPriority(priority int) SubmitOption

WithPriority sets the priority (higher = more urgent).

func WithTenantID

func WithTenantID(tenantID string) SubmitOption

WithTenantID sets the tenant ID.

type Uploader

type Uploader interface {
	Upload(ctx context.Context, report *ctis.Report) (*Result, error)
}

Uploader is the interface for uploading reports.

Jump to

Keyboard shortcuts

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