- Go 100%
| .gitignore | Initial commit | |
| go.mod | Updates for codeberg. | |
| go.sum | Adds go.mod | |
| LICENSE | Initial commit | |
| README.md | Updates for codeberg. | |
| task.go | Uses sync/atomic for reading/changing done state | |
| task_test.go | Renames crashed/done and IsCrashed/IsDone | |
| wrangler.go | Implements an Exists function | |
| wrangler_test.go | Adds Wrangler, one way of wrangling tasks | |
cronzilla
import "codeberg.org/mgkeller/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
typeErrTaskPanicErrorstruct{// contains filtered or unexported fields}ErrTaskPanicError is an error returned if a Task panics during Run
func (ErrTaskPanicError) Error
func(eErrTaskPanicError)Error()stringError returns the string message
type Task
typeTaskstruct{// Todo is a TaskFunc that gets called EveryTodoTaskFunc// Every is a Duration for how often Todo()Everytime.Duration// At is a Time to run Todo()Attime.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()boolIsDone 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(ctxcontext.Context,errorChanchanerror)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(errorChanchanerror)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
typeTaskFuncfunc()errorTaskFunc is a func that has no parameters and returns only error
func ErrorlessTaskFunc
funcErrorlessTaskFunc(ffunc())TaskFuncErrorlessTaskFunc wraps a func() into a TaskFunc TODO: Fix Name
type Wrangler
typeWranglerstruct{// contains filtered or unexported fields}Wrangler is a goro-safe aggregator for Tasks
func (*Wrangler) AddAt
func(w*Wrangler)AddAt(namestring,todoTaskFunc,attime.Time)<-chanerrorAddAt 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(namestring,todoTaskFunc,everytime.Duration)<-chanerrorAddEvery will include the named task to run every so often, returning an error channel to listen on
func (*Wrangler) Clean
func(w*Wrangler)Clean()intClean 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()intCount returns the current number of tasks being wrangled
func (*Wrangler) CountStale
func(w*Wrangler)CountStale()intCountStale returns the current number of wrangled tasks that have completed or crashed
func (*Wrangler) Delete
func(w*Wrangler)Delete(namestring)Delete will cancel and remove the named task from the Wrangler
func (*Wrangler) Exists
func(w*Wrangler)Exists(namestring)boolExists returns bool if the specified Task exists
func (*Wrangler) List
func(w*Wrangler)List()[]stringList will return a string array of Task names
func (*Wrangler) ListStale
func(w*Wrangler)ListStale()[]stringListStale will return a string array of Task names that have completed or crashed
Generated by godoc2md