poller

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 2 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNil

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.

Types

type Poller

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

Poller is a dedicated task that handles regular polling actions.

func New

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

New creates a simple poller.

func (*Poller) Action

func (poller *Poller) Action()

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

func (*Poller) Add

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

Add only replaces the action called method.

func (*Poller) Exists

func (poller *Poller) Exists() bool

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

func (*Poller) GetInterval

func (poller *Poller) GetInterval() int

GetInterval return the configured delay for the poller.

func (*Poller) Plop

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

func (poller *Poller) Restart()

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

func (*Poller) SetChanRestart

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

SetChanRestart set settings for the poller restart event.

func (*Poller) SetInterval

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

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

SetPostCheck callback actions to launch after the polling job.

func (*Poller) SetPreCheck

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

SetPreCheck callback actions to launch before the polling job.

func (*Poller) Start

func (poller *Poller) Start()

Start enable the polling ticker.

func (*Poller) Stop

func (poller *Poller) Stop()

Stop disable the polling ticker.

func (*Poller) Wait

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.

Jump to

Keyboard shortcuts

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