periodicjobs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package periodicjobs provides scheduled background jobs for the usernaut controller.

This file implements the user offboarding periodic job that automatically removes inactive users from all backend systems when they are no longer found in LDAP.

Index

Constants

View Source
const (
	// UserOffboardingJobName is the unique identifier for the user offboarding periodic job.
	UserOffboardingJobName = "usernaut_user_offboarding"

	// UserOffboardingJobInterval defines how often the user offboarding job runs.
	// Set to 24 hours to perform daily cleanup of inactive users.
	UserOffboardingJobInterval = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PeriodicTask

type PeriodicTask interface {
	Run(ctx context.Context) error
	GetInterval() time.Duration
	GetName() string
}

type PeriodicTaskManager

type PeriodicTaskManager struct {
	Tasks []PeriodicTask
}

func NewPeriodicTaskManager

func NewPeriodicTaskManager() *PeriodicTaskManager

NewPeriodicTaskManager creates a new PeriodicTaskManager used manage interval based tasks

func (*PeriodicTaskManager) AddTask

func (p *PeriodicTaskManager) AddTask(task PeriodicTask)

func (*PeriodicTaskManager) RunAll

func (p *PeriodicTaskManager) RunAll(ctx context.Context) error

RunAll runs all the tasks in the PeriodicTaskManager it launches a new goroutine for each task and stops when the context is canceled it uses a ticker to run the tasks at the specified interval (from the task) and stops when the context is canceled If interval == -1, the task is run only once.

type UserOffboardingJob

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

UserOffboardingJob implements a periodic job that monitors user activity and automatically offboards inactive users from all configured backends.

The job performs the following operations:

  1. Scans Redis cache for all user entries
  2. Verifies each user's status in LDAP directory
  3. Offboards users who are no longer active in LDAP from all backends
  4. Removes inactive users from the cache

This ensures that user access is automatically revoked when users leave the organization or become inactive in the LDAP directory.

func NewUserOffboardingJob

func NewUserOffboardingJob(
	sharedCacheMutex *sync.RWMutex,
	cacheClient cache.Cache,
	ldapClient ldap.LDAPClient,
	backendClients map[string]clients.Client,
) *UserOffboardingJob

NewUserOffboardingJob creates and initializes a new UserOffboardingJob instance.

This constructor:

  • Loads the application configuration
  • Initializes cache and LDAP clients
  • Sets up all enabled backend clients
  • Returns a fully configured job ready for execution

Parameters:

  • sharedCacheMutex: Shared mutex to prevent race conditions with other components
  • cacheClient: Shared cache client instance
  • ldapClient: Shared LDAP client instance
  • backendClients: Map of initialized backend clients

Returns:

  • *UserOffboardingJob: A configured job instance

func (*UserOffboardingJob) AddToPeriodicTaskManager

func (uoj *UserOffboardingJob) AddToPeriodicTaskManager(mgr *PeriodicTaskManager)

AddToPeriodicTaskManager registers this job with the provided periodic task manager.

This method integrates the user offboarding job into the controller's periodic task execution system, allowing it to run at the configured interval.

Parameters:

  • mgr: The PeriodicTaskManager instance to register this job with

func (*UserOffboardingJob) GetInterval

func (uoj *UserOffboardingJob) GetInterval() time.Duration

GetInterval returns the execution interval for this periodic job.

This method is required by the PeriodicTask interface and defines how often the user offboarding job should be executed.

Returns:

  • time.Duration: The interval between job executions (24 hours)

func (*UserOffboardingJob) GetName

func (uoj *UserOffboardingJob) GetName() string

GetName returns the unique name identifier for this periodic job.

This method is required by the PeriodicTask interface and provides a human-readable name for logging and monitoring purposes.

Returns:

  • string: The job name "usernaut_user_offboarding"

func (*UserOffboardingJob) Run

func (uoj *UserOffboardingJob) Run(ctx context.Context) error

Run executes the main user offboarding logic.

This method is required by the PeriodicTask interface and contains the core business logic for identifying and offboarding inactive users.

The execution flow:

  1. Retrieves all user keys from the cache
  2. Processes each user to check LDAP status
  3. Offboards users who are inactive in LDAP
  4. Reports execution results and any errors

Parameters:

  • ctx: Context for cancellation and logging

Returns:

  • error: Any fatal error that occurred during execution, or a summary of non-fatal errors if any users failed to process

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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