1
0
Fork
You've already forked go-cronzilla
0
No description
  • Go 100%
Find a file
2023年03月11日 09:37:58 -05:00
.gitignore Initial commit 2018年07月20日 11:10:50 -04:00
go.mod Updates for codeberg. 2023年03月11日 09:37:58 -05:00
go.sum Adds go.mod 2019年07月10日 10:38:01 -04:00
LICENSE Initial commit 2018年07月20日 11:10:50 -04:00
README.md Updates for codeberg. 2023年03月11日 09:37:58 -05:00
task.go Uses sync/atomic for reading/changing done state 2019年03月22日 19:09:43 -04:00
task_test.go Renames crashed/done and IsCrashed/IsDone 2018年07月22日 11:56:05 -04:00
wrangler.go Implements an Exists function 2019年04月27日 17:15:25 -04:00
wrangler_test.go Adds Wrangler, one way of wrangling tasks 2018年07月22日 11:43:14 -04:00

cronzilla

import "codeberg.org/mgkeller/go-cronzilla"

Overview

Index

Package files

task.go wrangler.go

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()string

Error 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()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(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()error

TaskFunc is a func that has no parameters and returns only error

func ErrorlessTaskFunc

funcErrorlessTaskFunc(ffunc())TaskFunc

ErrorlessTaskFunc 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)<-chanerror

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(namestring,todoTaskFunc,everytime.Duration)<-chanerror

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(namestring)

Delete will cancel and remove the named task from the Wrangler

func (*Wrangler) Exists

func(w*Wrangler)Exists(namestring)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