Documentation
¶
Index ¶
- Variables
- func CancelledByContext(ctx context.Context) bool
- func CompleteHandlerActivity(ctx context.Context, activityService Service, activityID string, ...)
- func FlushWriter(writer io.Writer)
- func NewWriter(ctx context.Context, activityService MessageAppender, activityID string, ...) io.Writer
- func RunHandlerActivity(ctx context.Context, activityService Service, opts HandlerOptions, ...) (string, error)
- func StartHandlerActivityForUser(ctx context.Context, activityService Service, environmentID string, ...) (string, context.Context)
- func WriteStartedLine(writer io.Writer, activityID string)
- type AppendMessageRequest
- type HandlerOptions
- type MessageAppender
- type Service
- type StartRequest
- type Tracker
- type UpdateRequest
- type Writer
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 FlushWriter ¶
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 ¶
Types ¶
type AppendMessageRequest ¶
type HandlerOptions ¶
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 Tracker ¶
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.