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 ¶
- Variables
- type Worker
- func (w *Worker) CalculateETDuration(ws *pkg.WaterSchedule) (time.Duration, bool)
- func (w *Worker) ExecuteGardenAction(g *pkg.Garden, input *action.GardenAction) error
- func (w *Worker) ExecuteLightAction(g *pkg.Garden, input *action.LightAction) error
- func (w *Worker) ExecuteScheduledWaterAction(g *pkg.Garden, z *pkg.Zone, ws *pkg.WaterSchedule, duration time.Duration) error
- func (w *Worker) ExecuteStopAction(g *pkg.Garden, input *action.StopAction) error
- func (w *Worker) ExecuteUpdateAction(g *pkg.Garden, input *action.UpdateAction) error
- func (w *Worker) ExecuteWaterAction(g *pkg.Garden, z *pkg.Zone, input *action.WaterAction) error
- func (w *Worker) ExecuteZoneAction(g *pkg.Garden, z *pkg.Zone, input *action.ZoneAction) error
- func (w *Worker) GetGardenHealth(ctx context.Context, g *pkg.Garden) *pkg.GardenHealth
- func (w *Worker) GetNextActiveWaterSchedule(waterSchedules []*pkg.WaterSchedule) *pkg.WaterSchedule
- func (w *Worker) GetNextWaterTime(ws *pkg.WaterSchedule) *time.Time
- func (w *Worker) RemoveJobsByID(id string) error
- func (w *Worker) ResetLightSchedule(g *pkg.Garden) error
- func (w *Worker) ResetWaterSchedule(ws *pkg.WaterSchedule) error
- func (w *Worker) ScaleWateringDuration(ws *pkg.WaterSchedule) (time.Duration, bool)
- func (w *Worker) ScheduleLightActions(g *pkg.Garden) error
- func (w *Worker) ScheduleWaterAction(waterSchedule *pkg.WaterSchedule) error
- func (w *Worker) StartAsync()
- func (w *Worker) Stop()
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
ExecuteGardenAction will execute a GardenAction
func (*Worker) ExecuteLightAction ¶
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 ¶
ExecuteStopAction sends the message over MQTT to the embedded garden controller
func (*Worker) ExecuteUpdateAction ¶
ExecuteUpdateAction sends an MQTT message to the garden controller with the current configuration
func (*Worker) ExecuteWaterAction ¶
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 ¶
ExecuteZoneAction will execute a ZoneAction
func (*Worker) GetGardenHealth ¶
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 ¶
RemoveJobsByID will remove Jobs tagged with the specific xid
func (*Worker) ResetLightSchedule ¶
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 ¶
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 ¶
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