Documentation
¶
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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
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 ¶
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 ¶
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 ¶
AddAt will include the named task to run specifically at the specified time, once, returning an error channel to listen on
func (*Wrangler) AddEvery ¶
AddEvery will include the named task to run every so often, returning an error channel to listen on
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) CountStale ¶
CountStale returns the current number of wrangled tasks that have completed or crashed