Documentation
¶
Index ¶
- func ConfigureDetached(cmd *exec.Cmd)
- type Handler
- func (h *Handler) DropExclude(ctx context.Context, p ipc.DropExcludeParams) (ipc.DropExcludeResult, error)
- func (h *Handler) Exclude(ctx context.Context, p ipc.ExcludeParams) (ipc.ExcludeResult, error)
- func (h *Handler) GetLogs(ctx context.Context, p ipc.GetLogsParams) (ipc.GetLogsResult, error)
- func (h *Handler) Priority(ctx context.Context, p ipc.PriorityParams) (ipc.PriorityResult, error)
- func (h *Handler) Shutdown(ctx context.Context, p ipc.ShutdownParams) (ipc.ShutdownResult, error)
- func (h *Handler) Status(ctx context.Context) (ipc.StatusResult, error)
- func (h *Handler) StreamLogs(ctx context.Context, conn *jsonrpc2.Conn, p ipc.GetLogsParams) error
- type RingBuffer
- type Supervisor
- func (s *Supervisor) DropExclude() []string
- func (s *Supervisor) Run(ctx context.Context) error
- func (s *Supervisor) Status(ctx context.Context) (ipc.StatusResult, error)
- func (s *Supervisor) UpdateDropExclude(ctx context.Context, p ipc.DropExcludeParams) (ipc.DropExcludeResult, error)
- func (s *Supervisor) UpdateDropProgress(drop *inventory.TimedDrop)
- func (s *Supervisor) UpdateExclude(ctx context.Context, p ipc.ExcludeParams) (ipc.ExcludeResult, error)
- func (s *Supervisor) UpdatePriority(ctx context.Context, p ipc.PriorityParams) (ipc.PriorityResult, error)
- type SupervisorOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureDetached ¶
ConfigureDetached configures cmd to run in a separate process group on POSIX systems.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements ipc.Handler by delegating to Supervisor and RingBuffer.
func NewHandler ¶
func NewHandler(sup *Supervisor, cancel context.CancelFunc, ring *RingBuffer) *Handler
NewHandler constructs an IPC handler wrapping the supervisor, shutdown cancel func, and log ring buffer.
func (*Handler) DropExclude ¶ added in v1.4.0
func (h *Handler) DropExclude(ctx context.Context, p ipc.DropExcludeParams) (ipc.DropExcludeResult, error)
DropExclude handles daemon.DropExclude requests by delegating to the supervisor.
func (*Handler) Exclude ¶ added in v1.3.0
func (h *Handler) Exclude(ctx context.Context, p ipc.ExcludeParams) (ipc.ExcludeResult, error)
Exclude handles daemon.Exclude requests by delegating to the supervisor.
func (*Handler) GetLogs ¶
func (h *Handler) GetLogs(ctx context.Context, p ipc.GetLogsParams) (ipc.GetLogsResult, error)
GetLogs returns the most recent log lines from the in-memory ring buffer.
func (*Handler) Priority ¶
func (h *Handler) Priority(ctx context.Context, p ipc.PriorityParams) (ipc.PriorityResult, error)
Priority queries or updates the priority games list.
func (*Handler) Shutdown ¶
func (h *Handler) Shutdown(ctx context.Context, p ipc.ShutdownParams) (ipc.ShutdownResult, error)
Shutdown initiates graceful termination by canceling the daemon context.
func (*Handler) StreamLogs ¶
StreamLogs subscribes to live log lines and forwards them as JSON-RPC notifications until canceled.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer stores a fixed-capacity in-memory log buffer and fans out writes to active subscribers.
func NewRingBuffer ¶
func NewRingBuffer(capacity int) *RingBuffer
NewRingBuffer creates a new RingBuffer holding up to capacity lines.
func (*RingBuffer) Lines ¶
func (r *RingBuffer) Lines(limit int) []string
Lines returns the last limit lines in chronological order. If limit <= 0, returns all lines.
func (*RingBuffer) Subscribe ¶
func (r *RingBuffer) Subscribe() (<-chan string, func())
Subscribe returns a channel of live log lines and a cancellation function.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor manages the long-lived campaign/channel selection and watch loop.
func NewProductionSupervisor ¶
func NewProductionSupervisor( gqlClient *gql.Client, userID int, logger *slog.Logger, priority, exclude []string, enableBadgesEmotes bool, opts ...SupervisorOption, ) *Supervisor
NewProductionSupervisor creates a Supervisor with standard production closures for Twitch GQL inventory.
func NewSupervisor ¶
func NewSupervisor( fetchInventory func(ctx context.Context) ([]inventory.DropsCampaign, error), resolveChannel func(ctx context.Context, c inventory.DropsCampaign, dropExclude ...string) (*model.Channel, error), logger *slog.Logger, priority, exclude []string, opts ...SupervisorOption, ) *Supervisor
NewSupervisor creates a Supervisor with injected fetch and resolve closures.
func (*Supervisor) DropExclude ¶ added in v1.4.0
func (s *Supervisor) DropExclude() []string
DropExclude returns a copy of the current drop-name/benefit keyword exclude list. It exists for callers like the watch-session runner, constructed before the Supervisor selects a campaign, that need the live list rather than whatever was configured at daemon startup.
func (*Supervisor) Run ¶
func (s *Supervisor) Run(ctx context.Context) error
Run runs the supervisor loop: select campaign -> resolve channel -> watch -> repeat.
func (*Supervisor) Status ¶
func (s *Supervisor) Status(ctx context.Context) (ipc.StatusResult, error)
Status returns a point-in-time snapshot of the daemon's operational state.
func (*Supervisor) UpdateDropExclude ¶ added in v1.4.0
func (s *Supervisor) UpdateDropExclude(ctx context.Context, p ipc.DropExcludeParams) (ipc.DropExcludeResult, error)
UpdateDropExclude updates or queries the drop-name/benefit keyword exclude list.
It mirrors UpdateExclude exactly — same lock, same persist-or-roll-back contract — for the same reason: a keyword that survives in memory but not on disk vanishes silently on restart. Matching against drop names/benefits is case-insensitive substring matching (see inventory.DropsCampaign.CanEarn), but the keyword list itself is deduplicated case-sensitively here, the same as priority/exclude.
func (*Supervisor) UpdateDropProgress ¶
func (s *Supervisor) UpdateDropProgress(drop *inventory.TimedDrop)
UpdateDropProgress updates the live active drop progress in the supervisor status.
func (*Supervisor) UpdateExclude ¶ added in v1.3.0
func (s *Supervisor) UpdateExclude(ctx context.Context, p ipc.ExcludeParams) (ipc.ExcludeResult, error)
UpdateExclude updates or queries the excluded game list.
It mirrors UpdatePriority exactly — same lock, same persist-or-roll-back contract — because an exclude that survives in memory but not on disk is the same trap as a priority that does: the operator sees the game disappear from selection, restarts, and it silently comes back.
Matching stays case-sensitive on Game.Name, the same comparison inventory.SelectCampaign performs; normalizing here would make the CLI accept entries that then never match a campaign.
func (*Supervisor) UpdatePriority ¶
func (s *Supervisor) UpdatePriority(ctx context.Context, p ipc.PriorityParams) (ipc.PriorityResult, error)
UpdatePriority updates or queries the priority game list.
type SupervisorOption ¶
type SupervisorOption func(*Supervisor)
SupervisorOption configures a Supervisor instance.
func WithConfigPath ¶ added in v1.1.0
func WithConfigPath(path string) SupervisorOption
WithConfigPath tells the Supervisor which config file to persist priority changes into. It must be the same file the running daemon loaded — the caller resolves it, rather than the Supervisor re-deriving a path that could differ from the one actually in use.
When unset, priority changes stay in memory only.
func WithDropExclude ¶ added in v1.4.0
func WithDropExclude(list []string) SupervisorOption
WithDropExclude seeds the initial drop-name/benefit keyword exclusion list. It is a SupervisorOption rather than a constructor positional argument (like priority/exclude) so existing NewSupervisor call sites do not need updating.
func WithEnableBadgesEmotes ¶ added in v1.2.0
func WithEnableBadgesEmotes(enabled bool) SupervisorOption
WithEnableBadgesEmotes sets whether badge/emote-reward campaigns are included in the eligible candidate pool, mirroring the enable_badges_emotes config setting read at startup. See Supervisor.enableBadgesEmotes's doc comment for why this is not live-updatable.
func WithReselectBackoff ¶
func WithReselectBackoff(d time.Duration) SupervisorOption
WithReselectBackoff overrides the duration to wait between selection attempts or watch cycles.
func WithWatchRunner ¶
func WithWatchRunner(fn func(ctx context.Context, campaign inventory.DropsCampaign, ch model.Channel) (*inventory.TimedDrop, error)) SupervisorOption
WithWatchRunner injects the runner function executed for each active watch session.