Documentation
¶
Index ¶
- Variables
- func AwaitHandlerActivitySlot(ctx context.Context, activityService Service, activityID, environmentID string)
- 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 StartQueuedHandlerActivityForUser(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 SlotWaiter
- 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 AwaitHandlerActivitySlot ¶ added in v2.5.0
func AwaitHandlerActivitySlot(ctx context.Context, activityService Service, activityID, environmentID string)
AwaitHandlerActivitySlot blocks until the queued activity holds a concurrency slot (flipping it to running). A cancellation while waiting is not an error to the caller: the work context is already cancelled, so the subsequent action fails fast and CompleteHandlerActivity records the cancelled status.
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 StartQueuedHandlerActivityForUser ¶ added in v2.5.0
func StartQueuedHandlerActivityForUser( 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)
StartQueuedHandlerActivityForUser behaves like StartHandlerActivityForUser but routes the activity through the per-environment concurrency limiter: when no slot is free the activity is created with status queued. The caller MUST call AwaitHandlerActivitySlot on the returned work context before doing the actual work (streaming endpoints write their started line in between, so the client learns the activity ID before the queue wait begins).
func WriteStartedLine ¶
Types ¶
type AppendMessageRequest ¶
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
// Queue routes the activity through the per-environment concurrency
// limiter so bulk long-running operations wait visibly instead of all
// running at once. Quick actions (start/stop/delete) must not set this.
Queue bool
}
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 SlotWaiter ¶ added in v2.5.0
type SlotWaiter interface {
AwaitActivitySlot(ctx context.Context, activityID, environmentID string) error
}
SlotWaiter is an optional interface a Service may implement to support per-environment activity concurrency limiting. AwaitActivitySlot blocks until the queued activity holds a slot (flipping its status to running), or returns the context cause when the wait is cancelled. The slot is released when the activity completes.
type StartRequest ¶
type StartRequest struct {
EnvironmentID string
// BatchID groups activities spawned by one logical user action. When nil,
// the batch ID attached to the request context (if any) is used instead.
BatchID *string
// Queue routes the activity through the per-environment concurrency
// limiter: with a free slot it starts running as usual; otherwise it is
// created with status queued and the caller must block on
// SlotWaiter.AwaitActivitySlot before doing the work.
Queue bool
Type models.ActivityType
ResourceType *string
ResourceID *string
ResourceName *string
StartedBy *models.User
Step string
LatestMessage string
Progress *int
Metadata models.JSON
}
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.