# README
go-cronzilla
cronzilla
import "github.com/cognusion/go-cronzilla"
Overview
Index
- type ErrTaskPanicError
- type Task
- type TaskFunc
- type Wrangler
- func (w *Wrangler) AddAt(name string, todo TaskFunc, at time.Time) <-chan error
- func (w *Wrangler) AddEvery(name string, todo TaskFunc, every time.Duration) <-chan error
- func (w *Wrangler) Clean() int
- func (w *Wrangler) Close()
- func (w *Wrangler) Count() int
- func (w *Wrangler) CountStale() int
- func (w *Wrangler) Delete(name string)
- func (w *Wrangler) Exists(name string) bool
- func (w *Wrangler) List() []string
- func (w *Wrangler) ListStale() []string
Package files
type ErrTaskPanicError
type ErrTaskPanicError struct {
// contains filtered or unexported fields
}
ErrTaskPanicError is an error returned if a Task panics during Run
func (ErrTaskPanicError) Error
func (e ErrTaskPanicError) Error() string
Error returns the string message
type Task
type Task struct {
// Todo is a TaskFunc that gets called Every
Todo TaskFunc
// Every is a Duration for how often Todo()
Every time.Duration
// At is a Time to run Todo()
At time.Time
// contains filtered or unexported fields
}
Task is our... task. Philosophically, Todo() is run in the goro executing Run(), so in general you should give it it's own. This is done because I believe that if your Task.Run() panics, even though we recover and gracefully handle it, that should be the end of your Task unless you call Run() again. Running Todo() in a separate goro would allow the Task to keep on executing a panic'y Todo(), but that's just not right. If that's important to you, you can write a re-Run()ing wrangler that handles panic cases for you.
func (*Task) IsDone
func (t *Task) IsDone() bool
IsDone returns an internal state bool that is set if Run() was called, but has exited because of crash, completion, or cancellation.
func (*Task) Run
func (t *Task) Run(ctx context.Context, errorChan chan error)
Run takes a context and error chan. If Every is non-zero, calls Todo() Every until the context expires or is cancelled. If At is non-zero, calls Todo() At. If both Every and At are defined, will do both. The error chan WILL BE CLOSED when the function exits, which is a good way to know that the task isn't running anymore, otherwise will only pass non-nil errors from Todo(). If the error is an ErrTaskPanicError, then Todo() panic'd, and the stack trace is returned on errorChan just before it is closed.
func (*Task) RunOnce
func (t *Task) RunOnce(errorChan chan error)
RunOnce takes an error chan, and calls Todo() once after an Every or At. The error chan WILL BE CLOSED when the function exits, which is a good way to know that the task isn't running anymore, otherwise will only pass non-nil errors from Todo(). If the error is an ErrTaskPanicError, then Todo() panic'd, and the stack trace is returned on errorChan just before it is closed.
type TaskFunc
type TaskFunc func() error
TaskFunc is a func that has no parameters and returns only error
func ErrorlessTaskFunc
func ErrorlessTaskFunc(f func()) TaskFunc
ErrorlessTaskFunc wraps a func() into a TaskFunc TODO: Fix Name
type Wrangler
type Wrangler struct {
// contains filtered or unexported fields
}
Wrangler is a goro-safe aggregator for Tasks
func (*Wrangler) AddAt
func (w *Wrangler) AddAt(name string, todo TaskFunc, at time.Time) <-chan error
AddAt will include the named task to run specifically at the specified time, once, returning an error channel to listen on
func (*Wrangler) AddEvery
func (w *Wrangler) AddEvery(name string, todo TaskFunc, every time.Duration) <-chan error
AddEvery will include the named task to run every so often, returning an error channel to listen on
func (*Wrangler) Clean
func (w *Wrangler) Clean() int
Clean will remove completed or crashed tasks
func (*Wrangler) Close
func (w *Wrangler) Close()
Close will cancel all of the tasks being wrangled. The Wrangler may be reused after Close is called
func (*Wrangler) Count
func (w *Wrangler) Count() int
Count returns the current number of tasks being wrangled
func (*Wrangler) CountStale
func (w *Wrangler) CountStale() int
CountStale returns the current number of wrangled tasks that have completed or crashed
func (*Wrangler) Delete
func (w *Wrangler) Delete(name string)
Delete will cancel and remove the named task from the Wrangler
func (*Wrangler) Exists
func (w *Wrangler) Exists(name string) bool
Exists returns bool if the specified Task exists
func (*Wrangler) List
func (w *Wrangler) List() []string
List will return a string array of Task names
func (*Wrangler) ListStale
func (w *Wrangler) ListStale() []string
ListStale will return a string array of Task names that have completed or crashed
Generated by godoc2md