Documentation
¶
Index ¶
- Constants
- Variables
- func CauseFromContext(ctx context.Context) (error, bool)
- func GetTaskDescription(task Task) string
- func GetTaskName(task Task) string
- func LoggerFromContext(ctx context.Context) *slog.Logger
- type BaseOverloadedTask
- type BaseWrappedTask
- type BuildHealthHandlerOption
- type CallbackStep
- type Future
- type FutureResolver
- type FutureValueOption
- type HealthHandler
- type Manager
- func (m *Manager) AddInitError(err error)
- func (m *Manager) AddService(stage string, service Service, options ...TaskOption)
- func (m *Manager) AddTask(stage string, task Task, options ...TaskOption)
- func (m *Manager) AddTaskFunc(stage string, f TaskFunc, options ...TaskOption)
- func (m *Manager) IsRunning() bool
- func (m *Manager) Run(ctx context.Context, options ...RunOption) error
- func (m *Manager) RunWithStopErrors(ctx context.Context, options ...RunOption) (cause error, stopErr error)
- func (m *Manager) Shutdown()
- func (m *Manager) Stages() []string
- type ManagerCallback
- type ManagerCallbackFunc
- type Option
- func WithAfterRun(afterRun func(ctx context.Context, cause error, stopErr error) error) Option
- func WithBeforeRun(beforeRun func(ctx context.Context) (context.Context, error)) Option
- func WithEnforceShutdownTimeout(enforceShutdownTimeout bool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithManagerCallback(callbacks ...ManagerCallback) Option
- func WithShutdownTimeout(shutdownTimeout time.Duration) Option
- func WithStages(stages ...string) Option
- func WithTaskCallback(callbacks ...TaskCallback) Option
- func WithTaskErrorHandler(handler TaskErrorHandler) Option
- func WithTeardownTimeout(teardownTimeout time.Duration) Option
- type RunOption
- type Service
- type ServiceName
- type ServiceTask
- type ServiceWithSetup
- type ServiceWithTeardown
- type SignalError
- type StartStepManager
- type Step
- type Task
- type TaskAndInstanceOption
- type TaskBuildDataFunc
- type TaskBuildDataOption
- func WithDataName[T any](name string) TaskBuildDataOption[T]
- func WithDataParent[T any](parent Task) TaskBuildDataOption[T]
- func WithDataParentFromSetup[T any](parentFromSetup bool) TaskBuildDataOption[T]
- func WithDataStart[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
- func WithDataStop[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
- func WithDataTaskOptions[T any](options ...TaskInstanceOption) TaskBuildDataOption[T]
- func WithDataTeardown[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
- type TaskBuildDataSetupFunc
- type TaskBuildFunc
- type TaskBuildOption
- func WithName(name string) TaskBuildOption
- func WithParent(parent Task) TaskBuildOption
- func WithSetup(f TaskBuildFunc) TaskBuildOption
- func WithStart(f TaskBuildFunc) TaskBuildOption
- func WithStep(step Step, f TaskBuildFunc) TaskBuildOption
- func WithStop(f TaskBuildFunc) TaskBuildOption
- func WithTaskOptions(options ...TaskInstanceOption) TaskBuildOption
- func WithTeardown(f TaskBuildFunc) TaskBuildOption
- type TaskCallback
- type TaskCallbackFunc
- type TaskErrorHandler
- type TaskFunc
- type TaskFuture
- type TaskHandler
- type TaskInstanceOption
- type TaskName
- type TaskOption
- type TaskSignalTask
- func (t *TaskSignalTask) Run(ctx context.Context, step Step) error
- func (t *TaskSignalTask) Signals() []os.Signal
- func (t *TaskSignalTask) String() string
- func (t *TaskSignalTask) TaskName() string
- func (t *TaskSignalTask) TaskOptions() []TaskInstanceOption
- func (t *TaskSignalTask) TaskSteps() []Step
- type TaskSteps
- type TaskTimeoutTask
- func (t *TaskTimeoutTask) Run(ctx context.Context, step Step) error
- func (t *TaskTimeoutTask) String() string
- func (t *TaskTimeoutTask) TaskName() string
- func (t *TaskTimeoutTask) TaskOptions() []TaskInstanceOption
- func (t *TaskTimeoutTask) TaskSteps() []Step
- func (t *TaskTimeoutTask) Timeout() time.Duration
- type TaskWithData
- type TaskWithInitError
- type TaskWithOptions
- type TaskWithWrapped
- type TimeoutError
- type TimeoutTaskOption
- type WrapTaskOption
Examples ¶
Constants ¶
const ( TaskNameSignals = "signals" TaskNameTimeout = "timeout" )
const (
StageDefault = "default"
)
Variables ¶
var ( ErrExit = errors.New("normal exit") ErrInvalidStage = errors.New("invalid stage") ErrInvalidTaskStep = errors.New("invalid step for task") ErrInvalidStepOrder = errors.New("invalid step order") ErrAlreadyRunning = errors.New("already running") ErrInitialization = errors.New("initialization error") ErrNoStartTask = errors.New("no start tasks available") ErrNilTask = errors.New("nil task") ErrNoStage = errors.New("no stages available") ErrShutdownTimeout = errors.New("shutdown timeout") ErrAlreadyInitialized = errors.New("already initialized") ErrNotInitialized = errors.New("not initialized") ErrDuplicateStep = errors.New("duplicate step") )
var ( ErrAlreadyResolved = errors.New("already resolved") ErrNotResolved = errors.New("not resolved") )
Functions ¶
func CauseFromContext ¶
CauseFromContext gets the stop cause from the context, if available. If not available, err is guaranteed to be nil.
func GetTaskDescription ¶ added in v3.2.0
GetTaskDescription returns the task description, be it the String method, a task name, or its variable type.
func GetTaskName ¶ added in v3.2.0
GetTaskName gets the name of task, or blank if it don't have one.
Types ¶
type BaseOverloadedTask ¶
type BaseOverloadedTask[T Task] struct { Task T }
BaseOverloadedTask wraps a task and forwards all task interface methods. It doesn't implement TaskWithWrapped.
func (*BaseOverloadedTask[T]) String ¶
func (t *BaseOverloadedTask[T]) String() string
func (*BaseOverloadedTask[T]) TaskName ¶ added in v3.2.0
func (t *BaseOverloadedTask[T]) TaskName() string
func (*BaseOverloadedTask[T]) TaskOptions ¶
func (t *BaseOverloadedTask[T]) TaskOptions() []TaskInstanceOption
func (*BaseOverloadedTask[T]) TaskSteps ¶
func (t *BaseOverloadedTask[T]) TaskSteps() []Step
type BaseWrappedTask ¶
type BaseWrappedTask[T Task] struct { *BaseOverloadedTask[T] }
BaseWrappedTask wraps a task and forwards all task interface methods. It implements TaskWithWrapped.
func NewBaseWrappedTask ¶
func NewBaseWrappedTask[T Task](task T) *BaseWrappedTask[T]
func (*BaseWrappedTask[T]) Run ¶
func (t *BaseWrappedTask[T]) Run(ctx context.Context, step Step) error
func (*BaseWrappedTask[T]) WrappedTask ¶
func (t *BaseWrappedTask[T]) WrappedTask() Task
type BuildHealthHandlerOption ¶ added in v3.7.1
type BuildHealthHandlerOption func(*buildHealthHandler)
func WithHealthHandlerServiceStarted ¶ added in v3.7.1
func WithHealthHandlerServiceStarted(f func(context.Context)) BuildHealthHandlerOption
func WithHealthHandlerServiceTerminating ¶ added in v3.7.1
func WithHealthHandlerServiceTerminating(f func(context.Context)) BuildHealthHandlerOption
type CallbackStep ¶
type CallbackStep int
CallbackStep defines the callback step (before or after the task step).
const ( CallbackStepBefore CallbackStep = iota CallbackStepAfter )
func (CallbackStep) String ¶
func (s CallbackStep) String() string
type Future ¶
type Future[T any] interface { // Value gets the resolved future value. // By default, it waits for the value to be resolved. Use the WithoutFutureWait option to prevent this. Value(options ...FutureValueOption) (T, error) // Done is a channel that is closed when the future value is resolved. Done() <-chan struct{} }
Future is a proxy for a result that will be resolved in the future.
type FutureResolver ¶
type FutureResolver[T any] interface { Future[T] // Resolve resolves the Future with the passed value. Resolve(value T) // ResolveError resolves the Future with the passed error. ResolveError(err error) }
FutureResolver is a resolvable Future.
func NewFuture ¶
func NewFuture[T any]() FutureResolver[T]
type FutureValueOption ¶
type FutureValueOption func(*futureValueOptions)
func WithFutureCtx ¶
func WithFutureCtx(ctx context.Context) FutureValueOption
WithFutureCtx adds a context to be checked if WithoutFutureWait is set.
func WithoutFutureWait ¶ added in v3.5.0
func WithoutFutureWait() FutureValueOption
WithoutFutureWait prevents [Future.Value] to wait for the future to be resolved. If the future was not resolved yet, ErrNotResolved will be returned.
type HealthHandler ¶ added in v3.6.0
type HealthHandler interface {
ServiceStarted(context.Context)
ServiceTerminating(ctx context.Context)
}
HealthHandler is a health handler definition that allows implementing probes.
func BuildHealthHandler ¶ added in v3.7.1
func BuildHealthHandler(options ...BuildHealthHandlerOption) HealthHandler
BuildHealthHandler builds a HealthHandler from callback functions.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the complete execution lifecycle.
Example ¶
package main
import (
"context"
"errors"
"fmt"
"net"
"net/http"
"os"
"syscall"
"time"
"github.com/rrgmc/svcinit/v3"
)
// healthService implements an HTTP server used to serve health probes.
type healthService struct {
server *http.Server
}
func newHealthService() *healthService {
return &healthService{
server: &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}),
Addr: ":8081",
},
}
}
func (s *healthService) Start(ctx context.Context) error {
s.server.BaseContext = func(net.Listener) context.Context {
return ctx
}
return s.server.ListenAndServe()
}
func (s *healthService) Stop(ctx context.Context) error {
return s.server.Shutdown(ctx)
}
func main() {
ctx := context.Background()
sinit, err := svcinit.New(
// initialization in 3 stages. Initialization is done in stage order, and shutdown in reverse stage order.
// all tasks added to the same stage are started/stopped in parallel.
svcinit.WithStages(svcinit.StageDefault, "manage", "service"),
// use a context with a 20-second cancellation during shutdown.
svcinit.WithShutdownTimeout(20*time.Second),
// some tasks may not check context cancellation, set enforce to true to give up waiting after the shutdown timeout.
// The default is true.
svcinit.WithEnforceShutdownTimeout(true),
)
if err != nil {
fmt.Println(err)
return
}
// add a task to start health HTTP server before the service, and stop it after.
sinit.AddTask("manage", svcinit.BuildDataTask[*healthService](
// the "BuildDataTask" setup callback returns an instance that is sent to all following steps.
func(ctx context.Context) (*healthService, error) {
return newHealthService(), nil
},
svcinit.WithDataStart(func(ctx context.Context, service *healthService) error {
return service.Start(ctx)
}),
svcinit.WithDataStop(func(ctx context.Context, service *healthService) error {
return service.Stop(ctx)
}),
))
// add a task to start the core HTTP server.
sinit.AddTask("service", svcinit.BuildDataTask[*http.Server](
func(ctx context.Context) (*http.Server, error) {
// initialize the service in the setup step.
// as this may take some time in bigger services, initializing here allows other tasks to initialize
// at the same time.
server := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}),
Addr: ":8080",
}
return server, nil
},
svcinit.WithDataStart(func(ctx context.Context, service *http.Server) error {
service.BaseContext = func(net.Listener) context.Context {
return ctx
}
return service.ListenAndServe()
}),
// stop the service. By default, the context is NOT cancelled, this method must arrange for the start
// function to end.
svcinit.WithDataStop(func(ctx context.Context, service *http.Server) error {
return service.Shutdown(ctx)
}),
))
// shutdown on OS signal.
sinit.AddTask(svcinit.StageDefault, svcinit.SignalTask(os.Interrupt, syscall.SIGTERM))
// sleep 100ms and shutdown.
sinit.AddTask(svcinit.StageDefault, svcinit.TimeoutTask(100*time.Millisecond,
svcinit.WithTimeoutTaskError(errors.New("timed out"))))
err = sinit.Run(ctx)
if err != nil {
fmt.Println("err:", err)
}
}
Output: err: timed out
func (*Manager) AddInitError ¶
func (*Manager) AddService ¶
func (m *Manager) AddService(stage string, service Service, options ...TaskOption)
AddService add a Service to be executed at the passed stage.
func (*Manager) AddTask ¶
func (m *Manager) AddTask(stage string, task Task, options ...TaskOption)
AddTask add a Task to be executed at the passed stage.
func (*Manager) AddTaskFunc ¶
func (m *Manager) AddTaskFunc(stage string, f TaskFunc, options ...TaskOption)
AddTaskFunc add a Task to be executed at the passed stage.
func (*Manager) Run ¶
Run executes the initialization and returns the error of the first task stop step that returns.
func (*Manager) RunWithStopErrors ¶
func (m *Manager) RunWithStopErrors(ctx context.Context, options ...RunOption) (cause error, stopErr error)
RunWithStopErrors executes the initialization and returns the error of the first task stop step that returns, and also any errors happening during shutdown in a wrapped error.
type ManagerCallback ¶
type ManagerCallback interface {
Callback(ctx context.Context, stage string, step Step, callbackStep CallbackStep)
}
ManagerCallback is a callback for manager events. A cause may be set in the context. Use CauseFromContext to check.
type ManagerCallbackFunc ¶
type ManagerCallbackFunc func(ctx context.Context, stage string, step Step, callbackStep CallbackStep)
func (ManagerCallbackFunc) Callback ¶
func (f ManagerCallbackFunc) Callback(ctx context.Context, stage string, step Step, callbackStep CallbackStep)
type Option ¶
type Option func(*Manager)
func WithAfterRun ¶ added in v3.6.0
WithAfterRun adds a callback to be executed after all stages run. The returned error will be the cause returned from Manager.Run. Return the same cause parameter as error to keep it.
func WithBeforeRun ¶ added in v3.6.0
WithBeforeRun adds a callback to be executed before stages are run. Return a changed context, or the same one received. Any error that is returned will abort the Manager.Run execution with the passed error.
func WithEnforceShutdownTimeout ¶
WithEnforceShutdownTimeout don't wait for all shutdown tasks to complete if they are over the shutdown timeout. Usually the shutdown timeout only sets a timeout in the context, but it can't guarantee that all tasks will follow it. Default is true.
func WithLogger ¶
func WithManagerCallback ¶
func WithManagerCallback(callbacks ...ManagerCallback) Option
WithManagerCallback adds a manager callback. Multiple callbacks may be added.
func WithShutdownTimeout ¶
WithShutdownTimeout sets a shutdown timeout. The default is 10 seconds. If less then or equal to 0, no shutdown timeout will be set.
func WithStages ¶
WithStages sets the initialization stages. The default value is "[StageDEFAULT]".
func WithTaskCallback ¶
func WithTaskCallback(callbacks ...TaskCallback) Option
WithTaskCallback adds a task callback. Multiple callbacks may be added.
func WithTaskErrorHandler ¶ added in v3.6.0
func WithTaskErrorHandler(handler TaskErrorHandler) Option
WithTaskErrorHandler sets a callback that can change the error returned from a task. This can be used for example to ignore errors that are not errors, like [http.ErrServerClosed].
func WithTeardownTimeout ¶ added in v3.3.2
WithTeardownTimeout sets a teardown timeout. If less then or equal to 0, makes it continue using the timeout set for shutdown instead of creating a new one. The default is 0.
type RunOption ¶
type RunOption func(options *runOptions)
func WithRunShutdownContext ¶
WithRunShutdownContext sets a context to use for shutdown. If not set, "context.WithoutCancel(baseContext)" will be used.
type Service ¶
Service is an abstraction of Task as an interface, for convenience. Use ServiceAsTask do the wrapping.
type ServiceName ¶ added in v3.3.2
type ServiceName interface {
TaskName
}
ServiceName allows services to have a name.
type ServiceTask ¶
ServiceTask allows getting the source Service of the Task.
func ServiceAsTask ¶
func ServiceAsTask(service Service) ServiceTask
ServiceAsTask wraps a Service into a Task.
type ServiceWithSetup ¶
ServiceWithSetup is a Service which has a Setup step.
type ServiceWithTeardown ¶ added in v3.3.2
ServiceWithTeardown is a Service which has a Teardown step.
type SignalError ¶
SignalError is returned from SignalTask if the signal was received.
func (SignalError) Error ¶
func (e SignalError) Error() string
type StartStepManager ¶
type StartStepManager interface {
ContextCancel(cause error) bool // cancel the "start" step context. Returns whether the cancellation was possible.
Finished() <-chan struct{} // channel that will be closed once the "start" step finishes.
FinishedErr() error // the error returned from the start step.
CanContextCancel() bool // returns whether the "start" step context can be called.
CanFinished() bool // returns whether the Finished channel can be checked. If false, Finished will return a nil channel.
}
StartStepManager allows the "stop" step to cancel the start step and/or wait for it to finish.
func StartStepManagerFromContext ¶
func StartStepManagerFromContext(ctx context.Context) StartStepManager
StartStepManagerFromContext returns a StartStepManager from the stop step's context. If not available returns a noop instance.
type Step ¶
type Step int
Step defines the possible task runnable steps.
func DefaultTaskSteps ¶
func DefaultTaskSteps() []Step
DefaultTaskSteps returns the default value for [TaskSteps.TaskSteps], which is the list of all steps.
type Task ¶
func BuildTask ¶
func BuildTask(options ...TaskBuildOption) Task
BuildTask creates a task from callback functions.
type TaskAndInstanceOption ¶
type TaskAndInstanceOption interface {
TaskOption
TaskInstanceOption
}
func WithCancelContext ¶
func WithCancelContext(cancelContext bool) TaskAndInstanceOption
WithCancelContext sets whether to automatically cancel the task start step context when the first task finishes. The default is false, meaning that the stop step should handle to stop the task.
func WithStartStepManager ¶
func WithStartStepManager() TaskAndInstanceOption
WithStartStepManager sets whether to add a StartStepManager to the stop step context. This allows the stop step to cancel the start step context and/or wait for its completion.
type TaskBuildDataOption ¶
type TaskBuildDataOption[T any] func(*taskBuildData[T])
func WithDataName ¶ added in v3.2.0
func WithDataName[T any](name string) TaskBuildDataOption[T]
WithDataName sets the task name.
func WithDataParent ¶
func WithDataParent[T any](parent Task) TaskBuildDataOption[T]
WithDataParent sets a parent task. Any step not set in the built task will be forwarded to it.
func WithDataParentFromSetup ¶
func WithDataParentFromSetup[T any](parentFromSetup bool) TaskBuildDataOption[T]
WithDataParentFromSetup sets a parent task from the result of the "setup" task. If this value doesn't implement Task, an initialization error will be issued.
func WithDataStart ¶
func WithDataStart[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
WithDataStart sets a callback for the "start" step.
func WithDataStop ¶
func WithDataStop[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
WithDataStop sets a callback for the "stop" step.
func WithDataTaskOptions ¶
func WithDataTaskOptions[T any](options ...TaskInstanceOption) TaskBuildDataOption[T]
WithDataTaskOptions sets default task options for the TaskOption interface.
func WithDataTeardown ¶
func WithDataTeardown[T any](f TaskBuildDataFunc[T]) TaskBuildDataOption[T]
WithDataTeardown sets a callback for the "teardown" step.
type TaskBuildDataSetupFunc ¶
type TaskBuildFunc ¶
type TaskBuildOption ¶
type TaskBuildOption func(*taskBuild)
func WithName ¶ added in v3.2.0
func WithName(name string) TaskBuildOption
WithName sets the task name.
func WithParent ¶
func WithParent(parent Task) TaskBuildOption
WithParent sets a parent task. Any step not set in the built task will be forwarded to it.
func WithSetup ¶
func WithSetup(f TaskBuildFunc) TaskBuildOption
WithSetup sets a callback for the "setup" step.
func WithStart ¶
func WithStart(f TaskBuildFunc) TaskBuildOption
WithStart sets a callback for the "start" step.
func WithStep ¶
func WithStep(step Step, f TaskBuildFunc) TaskBuildOption
WithStep sets the callback for a step.
func WithStop ¶
func WithStop(f TaskBuildFunc) TaskBuildOption
WithStop sets a callback for the "stop" step.
func WithTaskOptions ¶
func WithTaskOptions(options ...TaskInstanceOption) TaskBuildOption
WithTaskOptions sets default task options for the TaskOption interface.
func WithTeardown ¶
func WithTeardown(f TaskBuildFunc) TaskBuildOption
WithTeardown sets a callback for the "teardown" step.
type TaskCallback ¶
type TaskCallback interface {
Callback(ctx context.Context, task Task, stage string, step Step, callbackStep CallbackStep, err error)
}
TaskCallback is a callback for task events. err is only set for CallbackStepAfter.
type TaskCallbackFunc ¶
type TaskCallbackFunc func(ctx context.Context, task Task, stage string, step Step, callbackStep CallbackStep, err error)
func (TaskCallbackFunc) Callback ¶
func (f TaskCallbackFunc) Callback(ctx context.Context, task Task, stage string, step Step, callbackStep CallbackStep, err error)
type TaskErrorHandler ¶ added in v3.6.0
type TaskFuture ¶
TaskFuture is a Task with data where the return of the setup step will resolve the Future.
func NewTaskFuture ¶
func NewTaskFuture[T any](setupFunc TaskBuildDataSetupFunc[T], options ...TaskBuildDataOption[T]) TaskFuture[T]
type TaskHandler ¶
TaskHandler should call task.Run(ctx, step) and return its error. It can do any processing it needs before and after the call. WARNING: not calling the method, or calling it for any other step, will break the promise of never calling the steps out of order or multiple times.
type TaskInstanceOption ¶
type TaskInstanceOption interface {
// contains filtered or unexported methods
}
type TaskName ¶ added in v3.2.0
type TaskName interface {
TaskName() string
}
TaskName allows tasks to have a name.
type TaskOption ¶
type TaskOption interface {
// contains filtered or unexported methods
}
func WithCallback ¶
func WithCallback(callbacks ...TaskCallback) TaskOption
WithCallback adds callbacks for the task.
func WithHandler ¶
func WithHandler(handler TaskHandler) TaskOption
WithHandler adds a task handler.
type TaskSignalTask ¶
type TaskSignalTask struct {
// contains filtered or unexported fields
}
func SignalTask ¶
func SignalTask(signals ...os.Signal) *TaskSignalTask
SignalTask returns a task that returns when one of the passed OS signals is received.
func (*TaskSignalTask) Signals ¶
func (t *TaskSignalTask) Signals() []os.Signal
func (*TaskSignalTask) String ¶
func (t *TaskSignalTask) String() string
func (*TaskSignalTask) TaskName ¶ added in v3.2.0
func (t *TaskSignalTask) TaskName() string
func (*TaskSignalTask) TaskOptions ¶
func (t *TaskSignalTask) TaskOptions() []TaskInstanceOption
func (*TaskSignalTask) TaskSteps ¶
func (t *TaskSignalTask) TaskSteps() []Step
type TaskSteps ¶
type TaskSteps interface {
TaskSteps() []Step
}
TaskSteps returns the steps that the task implements. They will be the only ones called.
type TaskTimeoutTask ¶
type TaskTimeoutTask struct {
// contains filtered or unexported fields
}
func TimeoutTask ¶
func TimeoutTask(timeout time.Duration, options ...TimeoutTaskOption) *TaskTimeoutTask
TimeoutTask stops the task after the specified timeout, or the context is done. By default, a TimeoutError is returned on timeout.
func (*TaskTimeoutTask) String ¶
func (t *TaskTimeoutTask) String() string
func (*TaskTimeoutTask) TaskName ¶ added in v3.2.0
func (t *TaskTimeoutTask) TaskName() string
func (*TaskTimeoutTask) TaskOptions ¶
func (t *TaskTimeoutTask) TaskOptions() []TaskInstanceOption
func (*TaskTimeoutTask) TaskSteps ¶
func (t *TaskTimeoutTask) TaskSteps() []Step
func (*TaskTimeoutTask) Timeout ¶
func (t *TaskTimeoutTask) Timeout() time.Duration
type TaskWithData ¶ added in v3.7.1
func BuildDataTask ¶
func BuildDataTask[T any](setupFunc TaskBuildDataSetupFunc[T], options ...TaskBuildDataOption[T]) TaskWithData[T]
BuildDataTask creates a task from callback functions, where some data is created in the "setup" step and passed to all other steps.
type TaskWithInitError ¶
type TaskWithInitError interface {
TaskInitError() error
}
TaskWithInitError allows a task to report an initialization error. The error might be nil.
type TaskWithOptions ¶
type TaskWithOptions interface {
TaskOptions() []TaskInstanceOption
}
TaskWithOptions allows the task to set some of the task options. They have priority over options set via Manager.AddTask.
type TaskWithWrapped ¶
TaskWithWrapped is a task which was wrapped from another Task.
func WrapTask ¶
func WrapTask(task Task, options ...WrapTaskOption) TaskWithWrapped
WrapTask wraps a task in a TaskWithWrapped, allowing the handler to be customized.
type TimeoutError ¶
TimeoutError is returned by TimeoutTask by default.
func (TimeoutError) Error ¶
func (e TimeoutError) Error() string
type TimeoutTaskOption ¶
type TimeoutTaskOption func(task *TaskTimeoutTask)
func WithTimeoutTaskError ¶
func WithTimeoutTaskError(timeoutErr error) TimeoutTaskOption
WithTimeoutTaskError sets an error to be returned from the timeout task instead of TimeoutError.
func WithoutTimeoutTaskError ¶
func WithoutTimeoutTaskError() TimeoutTaskOption
WithoutTimeoutTaskError returns a nil error in case of timeout.
type WrapTaskOption ¶
type WrapTaskOption func(task *wrappedTask)
func WithWrapName ¶ added in v3.2.0
func WithWrapName(name string) WrapTaskOption
WithWrapName sets the task name.
func WithWrapTaskHandler ¶
func WithWrapTaskHandler(handler TaskHandler) WrapTaskOption
WithWrapTaskHandler sets an optional handler for the task.
