Documentation
¶
Overview ¶
Package repository provides data access for compensation records.
Index ¶
- type CompensationRecord
- type CompensationRepository
- type CompensationStatus
- type CompensationSummary
- type ListCompensationsFilter
- type MongoCompensationRepository
- func (r *MongoCompensationRepository) DeleteCompensationHistory(ctx context.Context, workflowID string) error
- func (r *MongoCompensationRepository) EnsureIndexes(ctx context.Context) error
- func (r *MongoCompensationRepository) GetCompensationHistory(ctx context.Context, workflowID string) ([]CompensationRecord, error)
- func (r *MongoCompensationRepository) GetCompensationRecord(ctx context.Context, recordID string) (*CompensationRecord, error)
- func (r *MongoCompensationRepository) GetCompensationSummary(ctx context.Context, workflowID string) (*CompensationSummary, error)
- func (r *MongoCompensationRepository) GetPendingCompensations(ctx context.Context, limit int) ([]CompensationRecord, error)
- func (r *MongoCompensationRepository) IncrementRetryCount(ctx context.Context, recordID string) error
- func (r *MongoCompensationRepository) ListCompensations(ctx context.Context, filter ListCompensationsFilter) ([]CompensationRecord, error)
- func (r *MongoCompensationRepository) MarkCompensationCompleted(ctx context.Context, recordID string) error
- func (r *MongoCompensationRepository) MarkCompensationFailed(ctx context.Context, recordID string, err error) error
- func (r *MongoCompensationRepository) MarkCompensationStarted(ctx context.Context, recordID string) error
- func (r *MongoCompensationRepository) SaveCompensationRecord(ctx context.Context, record *CompensationRecord) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompensationRecord ¶
type CompensationRecord struct {
ID string `json:"id" bson:"_id"`
WorkflowID string `json:"workflowId" bson:"workflowId"`
RunID string `json:"runId,omitempty" bson:"runId,omitempty"`
ActivityName string `json:"activityName" bson:"activityName"`
Status CompensationStatus `json:"status" bson:"status"`
Error string `json:"error,omitempty" bson:"error,omitempty"`
StartedAt time.Time `json:"startedAt,omitempty" bson:"startedAt,omitempty"`
CompletedAt time.Time `json:"completedAt,omitempty" bson:"completedAt,omitempty"`
Duration time.Duration `json:"duration,omitempty" bson:"duration,omitempty"`
Retries int `json:"retries" bson:"retries"`
CompensationData json.RawMessage `json:"compensationData,omitempty" bson:"compensationData,omitempty"`
Metadata map[string]string `json:"metadata,omitempty" bson:"metadata,omitempty"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}
CompensationRecord tracks a compensation operation and its state.
func NewCompensationRecord ¶
func NewCompensationRecord(workflowID, runID, activityName string) *CompensationRecord
NewCompensationRecord creates a new compensation record with defaults.
func (*CompensationRecord) MarkComplete ¶
func (r *CompensationRecord) MarkComplete()
MarkComplete sets the record status to completed.
func (*CompensationRecord) MarkFailed ¶
func (r *CompensationRecord) MarkFailed(err error)
MarkFailed sets the record status to failed with an error.
func (*CompensationRecord) MarkSkipped ¶
func (r *CompensationRecord) MarkSkipped()
MarkSkipped sets the record status to skipped.
func (*CompensationRecord) MarkStarted ¶
func (r *CompensationRecord) MarkStarted()
MarkStarted sets the record status to running.
type CompensationRepository ¶
type CompensationRepository interface {
// SaveCompensationRecord creates or updates a compensation record.
SaveCompensationRecord(ctx context.Context, record *CompensationRecord) error
// GetCompensationRecord retrieves a compensation record by ID.
GetCompensationRecord(ctx context.Context, recordID string) (*CompensationRecord, error)
// GetCompensationHistory retrieves all compensation records for a workflow.
GetCompensationHistory(ctx context.Context, workflowID string) ([]CompensationRecord, error)
// ListCompensations retrieves compensation records with filtering.
ListCompensations(ctx context.Context, filter ListCompensationsFilter) ([]CompensationRecord, error)
// MarkCompensationStarted updates record status to running.
MarkCompensationStarted(ctx context.Context, recordID string) error
// MarkCompensationCompleted updates record status to completed.
MarkCompensationCompleted(ctx context.Context, recordID string) error
// MarkCompensationFailed updates record status to failed with error.
MarkCompensationFailed(ctx context.Context, recordID string, err error) error
// GetCompensationSummary retrieves aggregated compensation statistics.
GetCompensationSummary(ctx context.Context, workflowID string) (*CompensationSummary, error)
// DeleteCompensationHistory removes all compensation records for a workflow.
DeleteCompensationHistory(ctx context.Context, workflowID string) error
// GetPendingCompensations retrieves all pending compensations for retry.
GetPendingCompensations(ctx context.Context, limit int) ([]CompensationRecord, error)
// IncrementRetryCount increments the retry counter for a compensation record.
IncrementRetryCount(ctx context.Context, recordID string) error
}
CompensationRepository defines the interface for compensation data access.
type CompensationStatus ¶
type CompensationStatus string
CompensationStatus represents the status of a compensation operation.
const ( StatusPending CompensationStatus = "pending" StatusRunning CompensationStatus = "running" StatusCompleted CompensationStatus = "completed" StatusFailed CompensationStatus = "failed" StatusSkipped CompensationStatus = "skipped" )
type CompensationSummary ¶
type CompensationSummary struct {
WorkflowID string `json:"workflowId"`
TotalCompensations int `json:"totalCompensations"`
Completed int `json:"completed"`
Failed int `json:"failed"`
Skipped int `json:"skipped"`
Pending int `json:"pending"`
}
CompensationSummary provides an aggregated view of compensation history.
type ListCompensationsFilter ¶
type ListCompensationsFilter struct {
WorkflowID string
ActivityName string
Status CompensationStatus
StartTime time.Time
EndTime time.Time
Limit int
Offset int
}
ListCompensationsFilter provides filtering options for listing compensations.
type MongoCompensationRepository ¶
type MongoCompensationRepository struct {
// contains filtered or unexported fields
}
MongoCompensationRepository implements CompensationRepository using MongoDB.
func NewMongoCompensationRepository ¶
func NewMongoCompensationRepository(db *mongo.Database) *MongoCompensationRepository
NewMongoCompensationRepository creates a new MongoDB-backed compensation repository.
func (*MongoCompensationRepository) DeleteCompensationHistory ¶
func (r *MongoCompensationRepository) DeleteCompensationHistory(ctx context.Context, workflowID string) error
DeleteCompensationHistory removes all compensation records for a workflow.
func (*MongoCompensationRepository) EnsureIndexes ¶
func (r *MongoCompensationRepository) EnsureIndexes(ctx context.Context) error
EnsureIndexes creates the necessary indexes for the compensation collection.
func (*MongoCompensationRepository) GetCompensationHistory ¶
func (r *MongoCompensationRepository) GetCompensationHistory(ctx context.Context, workflowID string) ([]CompensationRecord, error)
GetCompensationHistory retrieves all compensation records for a workflow.
func (*MongoCompensationRepository) GetCompensationRecord ¶
func (r *MongoCompensationRepository) GetCompensationRecord(ctx context.Context, recordID string) (*CompensationRecord, error)
GetCompensationRecord retrieves a compensation record by ID.
func (*MongoCompensationRepository) GetCompensationSummary ¶
func (r *MongoCompensationRepository) GetCompensationSummary(ctx context.Context, workflowID string) (*CompensationSummary, error)
GetCompensationSummary retrieves aggregated compensation statistics.
func (*MongoCompensationRepository) GetPendingCompensations ¶
func (r *MongoCompensationRepository) GetPendingCompensations(ctx context.Context, limit int) ([]CompensationRecord, error)
GetPendingCompensations retrieves all pending compensations for retry.
func (*MongoCompensationRepository) IncrementRetryCount ¶
func (r *MongoCompensationRepository) IncrementRetryCount(ctx context.Context, recordID string) error
IncrementRetryCount increments the retry counter for a compensation record.
func (*MongoCompensationRepository) ListCompensations ¶
func (r *MongoCompensationRepository) ListCompensations(ctx context.Context, filter ListCompensationsFilter) ([]CompensationRecord, error)
ListCompensations retrieves compensation records with filtering.
func (*MongoCompensationRepository) MarkCompensationCompleted ¶
func (r *MongoCompensationRepository) MarkCompensationCompleted(ctx context.Context, recordID string) error
MarkCompensationCompleted updates record status to completed.
func (*MongoCompensationRepository) MarkCompensationFailed ¶
func (r *MongoCompensationRepository) MarkCompensationFailed(ctx context.Context, recordID string, err error) error
MarkCompensationFailed updates record status to failed with error.
func (*MongoCompensationRepository) MarkCompensationStarted ¶
func (r *MongoCompensationRepository) MarkCompensationStarted(ctx context.Context, recordID string) error
MarkCompensationStarted updates record status to running.
func (*MongoCompensationRepository) SaveCompensationRecord ¶
func (r *MongoCompensationRepository) SaveCompensationRecord(ctx context.Context, record *CompensationRecord) error
SaveCompensationRecord creates or updates a compensation record.