worker

package
v0.0.0-...-6f84274 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package worker handles scheduled watering, health checks, and notifications

Package worker handles scheduled watering, health checks, and notifications

Package worker handles scheduled watering, health checks, and notifications

Index

Constants

This section is empty.

Variables

View Source
var CreateNewID = xid.New

CreateNewID can be overridden for mocking

Functions

This section is empty.

Types

type Worker

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

Worker contains the necessary clients to schedule and execute actions

func NewWorker

func NewWorker(
	storageClient *storage.Client,
	influxdbClient influxdb.Client,
	mqttClient mqtt.Client,
	logger *slog.Logger,
) *Worker

NewWorker creates a Worker with specified clients

func (*Worker) CalculateETDuration

func (w *Worker) CalculateETDuration(ws *pkg.WaterSchedule) (time.Duration, bool)

CalculateETDuration calculates watering duration based on ET data using the citrus tree formula. Returns (duration, true) if ET calculation succeeds, (0, false) otherwise. This completely overrides the configured duration when successful.

func (*Worker) ExecuteGardenAction

func (w *Worker) ExecuteGardenAction(g *pkg.Garden, input *action.GardenAction) error

ExecuteGardenAction will execute a GardenAction

func (*Worker) ExecuteLightAction

func (w *Worker) ExecuteLightAction(g *pkg.Garden, input *action.LightAction) error

ExecuteLightAction sends an MQTT message to the garden controller to change the state of the light

func (*Worker) ExecuteScheduledWaterAction

func (w *Worker) ExecuteScheduledWaterAction(g *pkg.Garden, z *pkg.Zone, ws *pkg.WaterSchedule, duration time.Duration) error

ExecuteScheduledWaterAction will run ExecuteWaterAction after checking SkipCount

func (*Worker) ExecuteStopAction

func (w *Worker) ExecuteStopAction(g *pkg.Garden, input *action.StopAction) error

ExecuteStopAction sends the message over MQTT to the embedded garden controller

func (*Worker) ExecuteUpdateAction

func (w *Worker) ExecuteUpdateAction(g *pkg.Garden, input *action.UpdateAction) error

ExecuteUpdateAction sends an MQTT message to the garden controller with the current configuration

func (*Worker) ExecuteWaterAction

func (w *Worker) ExecuteWaterAction(g *pkg.Garden, z *pkg.Zone, input *action.WaterAction) error

ExecuteWaterAction sends the message over MQTT to the embedded garden controller. This is used for a directly-requested WaterAction and does not perform any of the watering checks that are usuall done for a scheduled watering

func (*Worker) ExecuteZoneAction

func (w *Worker) ExecuteZoneAction(g *pkg.Garden, z *pkg.Zone, input *action.ZoneAction) error

ExecuteZoneAction will execute a ZoneAction

func (*Worker) GetGardenHealth

func (w *Worker) GetGardenHealth(ctx context.Context, g *pkg.Garden) *pkg.GardenHealth

GetGardenHealth returns a GardenHealth struct after querying InfluxDB for the Garden controller's last contact time

func (*Worker) GetNextActiveWaterSchedule

func (w *Worker) GetNextActiveWaterSchedule(waterSchedules []*pkg.WaterSchedule) *pkg.WaterSchedule

GetNextActiveWaterSchedule determines the WaterSchedule that is going to be used for the next watering time

func (*Worker) GetNextWaterTime

func (w *Worker) GetNextWaterTime(ws *pkg.WaterSchedule) *time.Time

GetNextWaterTime determines the next scheduled watering time for a given Zone using tags

func (*Worker) RemoveJobsByID

func (w *Worker) RemoveJobsByID(id string) error

RemoveJobsByID will remove Jobs tagged with the specific xid

func (*Worker) ResetLightSchedule

func (w *Worker) ResetLightSchedule(g *pkg.Garden) error

ResetLightSchedule will simply remove the existing Job and create a new one

func (*Worker) ResetWaterSchedule

func (w *Worker) ResetWaterSchedule(ws *pkg.WaterSchedule) error

ResetWaterSchedule will simply remove the existing Job and create a new one

func (*Worker) ScaleWateringDuration

func (w *Worker) ScaleWateringDuration(ws *pkg.WaterSchedule) (time.Duration, bool)

ScaleWateringDuration returns a new watering duration based on weather scaling. It will not return any errors if they are encountered because there are multiple factors impacting watering. If ET control is configured and succeeds, it provides the base duration which can then be scaled by temperature and rain controls if they are also configured.

func (*Worker) ScheduleLightActions

func (w *Worker) ScheduleLightActions(g *pkg.Garden) error

ScheduleLightActions will schedule LightActions to turn the light on and off based off the CreatedAt date, LightSchedule time, and Interval. The scheduled Jobs are tagged with the Garden's ID so they can easily be removed

func (*Worker) ScheduleWaterAction

func (w *Worker) ScheduleWaterAction(waterSchedule *pkg.WaterSchedule) error

ScheduleWaterAction will schedule water actions for the Zone based off the CreatedAt date, WaterSchedule time, and Interval. The scheduled Job is tagged with the Zone's ID so it can easily be removed

func (*Worker) StartAsync

func (w *Worker) StartAsync()

StartAsync starts the Worker's background jobs

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the Worker's background jobs

Jump to

Keyboard shortcuts

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