lease

package
v0.0.0-...-0a5bd71 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	ExpireAt time.Time
	User     string
	Reason   string
}

Document represents a Firestore document representing a lease.

type Manager

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

Manager handles a lease document and manages the lease state.

func NewManager

func NewManager(ctx context.Context, logger *logging.Logger, guaranteedUntil time.Time, docRef *firestore.DocumentRef) *Manager

NewManager creates a new lease watcher.

  • guaranteedUntil is the time until which the lease is guaranteed to be active
  • if guaranteedUntil is in the past, the lease is disabled immediately
  • if guaranteedUntil is in the future, the lease is enabled until that time
  • to handle changes to the lease, WatchLease must be called
  • start the lease manager in a goroutine to watch the lease until the context is canceled

func (*Manager) SlogLogger

func (m *Manager) SlogLogger() *slog.Logger

SlogLogger returns a slog.Logger that writes to both stdout and the logger.

  • always logs to stdout
  • logs to the logger only when the lease is enabled or the initial lease time has not yet expired

func (*Manager) StderrWriter

func (m *Manager) StderrWriter() io.Writer

StderrWriter returns an io.Writer that writes to both stderr and the logger.

  • it always writes all messages to stderr and the logger, regardless of the lease state
  • logs are all written as ERROR level

func (*Manager) StdoutWriter

func (m *Manager) StdoutWriter() io.Writer

StdoutWriter returns an io.Writer that writes to both stdout and the logger.

  • it writes to stdout only when the lease is enabled or the initial lease time has not yet expired
  • logs are all written as INFO level

func (*Manager) Write

func (m *Manager) Write(p []byte) (n int, err error)

Write writes a log message directly to the logger if the lease is active

  • if the lease is not active, the message is discarded

Jump to

Keyboard shortcuts

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