godock: github.com/sqp/godock/libs/poller Index | Files

package poller

import "github.com/sqp/godock/libs/poller"

Package poller is a dedicated task that handles regular polling actions.

It does not start a loop, just handles the ticker and restart channels. You will have to get those with Start and GetRestart and use them in a loop. This job is generally done by the dock.StartApplet action, so you better use it or copy and extend it to your needs.

Display and user information related to the result of the check must be made using some return callback at the end of the check task.

Display and user information related to the check action itself, like displaying an activity emblem during the check, should be done using the PreCheck and PostCheck callbacks.

The goal is to keep each part separated and dedicated to one task. If we split each role and keep it agnostic of others, we can have easier debuging and evolution of our applets:

* The poller send timing events.
* The check task pull its data and send the results on a OnResult callback.
* The OnResult callback sorts the data and dispatch it to the renderers or alert interfaces.
* Renderer interfaces displays to the user informations or alerts the way he prefers.

Index

Package Files

poller.go

func NewNil Uses

func NewNil(add func(call func()) cdtype.AppPoller) cdtype.AppPoller

NewNil creates an empty poller with the ability to replace himself with a real poller when using the Add method.

Set the add method with a call that will create a real poller.

type Poller Uses

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

Poller is a dedicated task that handles regular polling actions.

func New Uses

func New(callCheck func(), log cdtype.Logger) *Poller

New creates a simple poller.

func (*Poller) Action Uses

func (poller *Poller) Action()

Action launch the check action. Triggers PreCheck, OnCheck and PostCheck callbacks in this order.

func (*Poller) Add Uses

func (poller *Poller) Add(callCheck func()) cdtype.AppPoller

Add only replaces the action called method.

func (*Poller) Exists Uses

func (poller *Poller) Exists() bool

Exists returns true if the poller exists (isn't nil).

func (*Poller) GetInterval Uses

func (poller *Poller) GetInterval() int

GetInterval return the configured delay for the poller.

func (*Poller) Plop Uses

func (poller *Poller) Plop() bool

Plop increase the counter and launch the action if it reached the interval. The counter is also reset if the action is launched. Safe to use on nil poller.

func (*Poller) Restart Uses

func (poller *Poller) Restart()

Restart resets the counter and launch Action in a goroutine. Safe to use on nil poller.

func (*Poller) SetChanRestart Uses

func (poller *Poller) SetChanRestart(c chan string, name string)

SetChanRestart set settings for the poller restart event.

func (*Poller) SetInterval Uses

func (poller *Poller) SetInterval(delay ...int) int

SetInterval sets the polling interval time, in seconds. You can add a default value as a second argument to be sure you will have a valid value (> 0).

func (*Poller) SetPostCheck Uses

func (poller *Poller) SetPostCheck(onFinished func())

SetPostCheck callback actions to launch after the polling job.

func (*Poller) SetPreCheck Uses

func (poller *Poller) SetPreCheck(onStarted func())

SetPreCheck callback actions to launch before the polling job.

func (*Poller) Start Uses

func (poller *Poller) Start()

Start enable the polling ticker.

func (*Poller) Stop Uses

func (poller *Poller) Stop()

Stop disable the polling ticker.

func (*Poller) Wait Uses

func (poller *Poller) Wait() <-chan time.Time

Wait return a channel that will be triggered after the defined poller interval. You will have to call it on every loop as it not a real ticker. It's just a single use chan.

Package poller imports 2 packages (graph) and is imported by 1 packages. Updated 2017-10-01. Refresh now. Tools for package owners.