worker

package
v0.0.0-...-aeec7d0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

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

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) 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

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

ExecuteStopAction sends the message over MQTT to the embedded garden controller

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) 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

func (w *Worker) GetNextLightTime(g *pkg.Garden, state pkg.LightState) *time.Time

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

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

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) ScheduleLightDelay

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

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

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