eventhandler

package
v1.74.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package eventhandler provides event handling for Kubernetes and schedule events. It converts events from multiple sources into queue tasks for processing.

The Handler orchestrates events from:

  • Kubernetes resources (via kubeEventsManager)
  • Scheduled cron jobs (via scheduleManager)

Thread Safety: The Handler uses sync.Once to ensure Start() can only execute once, preventing goroutine leaks and race conditions from multiple Start() calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	KubeEventsManager kubeeventsmanager.KubeEventsManager
	ScheduleManager   schedulemanager.ScheduleManager
	PackageManager    *packagemanager.Manager
	QueueService      *queue.Service
}

type Handler

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

Handler manages the event processing loop for Kubernetes and schedule events. It listens to events from multiple sources and enqueues tasks for processing.

Lifecycle:

  • Create with New()
  • Start event processing with Start() (can only be called once due to sync.Once)
  • Stop event processing with Stop() (waits for goroutine to finish)

Thread Safety:

  • Start() is protected by sync.Once to prevent multiple goroutines
  • Stop() uses WaitGroup to ensure graceful shutdown
  • Context fields are written in once.Do() before goroutine reads them

func New

func New(conf Config, logger *log.Logger) *Handler

New creates a new Handler with the given configuration. The returned Handler is ready to be started with Start().

Initializes:

  • WaitGroup for tracking the event processing goroutine
  • sync.Once to ensure Start() executes only once

Note: The handler's context and cancel function are set when Start() is called first time.

func (*Handler) Start

func (h *Handler) Start() *Handler

Start begins the event processing loop in a new goroutine.

Events are converted to tasks via kubeTasks and scheduleTasks callbacks, then enqueued to the queue service for processing.

Thread Safety:

  • Protected by sync.Once - subsequent calls to Start() are no-ops
  • WaitGroup is incremented before spawning goroutine (Add called before Do)
  • Context is set inside once.Do() before goroutine uses it

The goroutine runs until:

  • h.ctx is cancelled (via Stop())
  • One of the event channels closes (abnormal termination)

To stop the handler, call Stop() which waits for goroutine completion.

func (*Handler) Stop

func (h *Handler) Stop()

Stop gracefully shuts down the event handler. It cancels the handler's context to signal the event loop to terminate, then waits for the goroutine to finish processing.

This method is safe to call even if Start() was never called or called multiple times, as sync.Once ensures the goroutine is created at most once.

Blocks until the event processing goroutine exits.

Jump to

Keyboard shortcuts

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