// Package orm define database data struct package orm import ( "github.com/gofrs/uuid" ) // AsyncTaskResult stores computation results, separate from AsyncTask model for flexibility type AsyncTaskResult struct { TaskID uuid.UUID `gorm:"column:task_id;primaryKey;type:uuid"` Result JSONMap `gorm:"column:result;type:jsonb"` ErrorCode *int `gorm:"column:error_code"` ErrorMessage *string `gorm:"column:error_message;type:text"` ErrorDetail JSONMap `gorm:"column:error_detail;type:jsonb"` } // TableName returns the table name for AsyncTaskResult model func (a *AsyncTaskResult) TableName() string { return "async_task_result" } // SetSuccess sets the result for successful task execution func (a *AsyncTaskResult) SetSuccess(result JSONMap) { a.Result = result a.ErrorCode = nil a.ErrorMessage = nil a.ErrorDetail = nil } // SetError sets the error information for failed task execution func (a *AsyncTaskResult) SetError(code int, message string, detail JSONMap) { a.Result = nil a.ErrorCode = &code a.ErrorMessage = &message a.ErrorDetail = detail } // HasError checks if the task result contains an error func (a *AsyncTaskResult) HasError() bool { return a.ErrorCode != nil || a.ErrorMessage != nil } // GetErrorCode returns the error code or 0 if no error func (a *AsyncTaskResult) GetErrorCode() int { if a.ErrorCode == nil { return 0 } return *a.ErrorCode } // GetErrorMessage returns the error message or empty string if no error func (a *AsyncTaskResult) GetErrorMessage() string { if a.ErrorMessage == nil { return "" } return *a.ErrorMessage } // IsSuccess checks if the task execution was successful func (a *AsyncTaskResult) IsSuccess() bool { return !a.HasError() } // Clear clears all result data func (a *AsyncTaskResult) Clear() { a.Result = nil a.ErrorCode = nil a.ErrorMessage = nil a.ErrorDetail = nil }