Documentation ¶
Index ¶
- type Worker
- 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) error
- func (w *Worker) ExecuteStopAction(g *pkg.Garden, input *action.StopAction) 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) GetNextActiveWaterSchedule(waterSchedules []*pkg.WaterSchedule) *pkg.WaterSchedule
- func (w *Worker) GetNextLightTime(g *pkg.Garden, state pkg.LightState) *time.Time
- 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) ScheduleLightDelay(g *pkg.Garden, input *action.LightAction) error
- func (w *Worker) ScheduleWaterAction(waterSchedule *pkg.WaterSchedule) error
- func (w *Worker) StartAsync()
- func (w *Worker) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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) 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) error
ExecuteScheduledWaterAction will get all of the Zones that use the schedule and execute WaterActions on them after scaling durations based on the Zone's configuration
func (*Worker) ExecuteStopAction ¶
ExecuteStopAction sends the message over MQTT to the embedded garden controller
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) 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) GetNextLightTime ¶
GetNextLightTime returns the next time that the Garden's light will be turned to the specified state
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
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) ScheduleLightDelay ¶
ScheduleLightDelay handles a LightAction that requests delaying turning a light on
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