activity

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("activity cancelled by user")

ErrCanceled is the cancellation cause set on an activity's work context when a user requests cancellation. Completion paths read context.Cause to record a cancelled (rather than failed) terminal status.

Functions

func CancelledByContext

func CancelledByContext(ctx context.Context) bool

CancelledByContext reports whether ctx was cancelled by a user cancellation request (as opposed to app shutdown or a deadline). Callers that finalize an activity from a possibly-cancelled work context use this to choose between a cancelled and a failed terminal status.

func CompleteHandlerActivity

func CompleteHandlerActivity(ctx context.Context, activityService Service, activityID string, successMessage string, err error)

func FlushWriter

func FlushWriter(writer io.Writer)

func NewWriter

func NewWriter(ctx context.Context, activityService MessageAppender, activityID string, writer io.Writer, defaultStep string) io.Writer

func RunHandlerActivity

func RunHandlerActivity(ctx context.Context, activityService Service, opts HandlerOptions, action func(ctx context.Context) error) (string, error)

RunHandlerActivity starts an activity, runs action with the activity's work context (cancelable when the service supports it), and completes the activity. The action MUST use the provided context for its operation so cancellation propagates.

func StartHandlerActivityForUser

func StartHandlerActivityForUser(
	ctx context.Context,
	activityService Service,
	environmentID string,
	activityType models.ActivityType,
	resourceType string,
	resourceID string,
	resourceName string,
	user *models.User,
	step string,
	message string,
	metadata models.JSON,
) (string, context.Context)

StartHandlerActivityForUser creates a background activity and returns its ID along with a work context the caller MUST use for the underlying operation. When the service supports cancellation (implements Tracker), the returned context is a cancelable child bound to the activity; cancelling the activity cancels this context. The activity registration is released when the activity is completed via the service. On failure it returns ("", ctx) unchanged.

func WriteStartedLine

func WriteStartedLine(writer io.Writer, activityID string)

Types

type AppendMessageRequest

type AppendMessageRequest struct {
	Level    models.ActivityMessageLevel
	Message  string
	Payload  models.JSON
	Progress *int
	Step     string
}

type HandlerOptions

type HandlerOptions struct {
	EnvironmentID  string
	Type           models.ActivityType
	ResourceType   string
	ResourceID     string
	ResourceName   string
	User           *models.User
	Step           string
	Message        string
	SuccessMessage string
	Metadata       models.JSON
}

type MessageAppender

type MessageAppender interface {
	AppendMessage(ctx context.Context, activityID string, req AppendMessageRequest) (*activitytypes.Message, error)
}

type Service

type Service interface {
	StartActivity(ctx context.Context, req StartRequest) (*activitytypes.Activity, error)
	CompleteActivity(ctx context.Context, activityID string, status models.ActivityStatus, finalMessage string, errMessage *string, finalStep ...string) (*activitytypes.Activity, error)
}

type StartRequest

type StartRequest struct {
	EnvironmentID string
	Type          models.ActivityType
	ResourceType  *string
	ResourceID    *string
	ResourceName  *string
	StartedBy     *models.User
	Step          string
	LatestMessage string
	Progress      *int
	Metadata      models.JSON
}

type Tracker

type Tracker interface {
	Track(ctx context.Context, activityID string) context.Context
}

Tracker is an optional interface a Service may implement to make activities cancelable. Track derives a cancelable context bound to the activity ID and registers it so the activity can later be cancelled via the activity service. Implementers release the registration when the activity completes.

type UpdateRequest

type UpdateRequest struct {
	Status        models.ActivityStatus
	Progress      *int
	Step          *string
	LatestMessage *string
	Error         *string
	Metadata      models.JSON
}

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func (*Writer) Flush

func (w *Writer) Flush()

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL