Documentation
¶
Overview ¶
Package workflowmodule wraps github.com/weedbox/workflow as a weedbox/Fx module. It wires the engine and the GORM-backed store to the injected database.DatabaseConnector, auto-migrates the workflow tables on startup, and exposes a WorkflowManager that callers inject into their own modules.
Index ¶
- Constants
- Variables
- func Module(scope string, opts ...Option) fx.Option
- type Application
- type ApproverResolver
- type ApproverResolverFunc
- type Option
- type Params
- type ReviewLog
- type WorkflowManager
- func (m *WorkflowManager) Approve(ctx context.Context, applicationID, operatorID string) (workflow.Application, workflow.ReviewLog, error)
- func (m *WorkflowManager) CreateDraft(ctx context.Context, app workflow.Application) error
- func (m *WorkflowManager) Engine() *workflow.WorkflowEngine
- func (m *WorkflowManager) GetApplication(ctx context.Context, applicationID string) (workflow.Application, error)
- func (m *WorkflowManager) GetTemplate(ctx context.Context, templateID string) (workflow.WorkflowTemplate, error)
- func (m *WorkflowManager) ListLogs(ctx context.Context, applicationID string) ([]workflow.ReviewLog, error)
- func (m *WorkflowManager) RejectClose(ctx context.Context, applicationID, operatorID, comment string) (workflow.Application, workflow.ReviewLog, error)
- func (m *WorkflowManager) Resubmit(ctx context.Context, applicationID string) (workflow.Application, workflow.ReviewLog, error)
- func (m *WorkflowManager) Return(ctx context.Context, applicationID, operatorID, comment string) (workflow.Application, workflow.ReviewLog, error)
- func (m *WorkflowManager) SaveTemplate(ctx context.Context, tpl workflow.WorkflowTemplate) error
- func (m *WorkflowManager) Service() *workflow.Service
- func (m *WorkflowManager) SetResolver(r workflow.ApproverResolver)
- func (m *WorkflowManager) Store() *gormstore.Store
- func (m *WorkflowManager) Submit(ctx context.Context, applicationID string) (workflow.Application, workflow.ReviewLog, error)
- type WorkflowModule
- type WorkflowStage
- type WorkflowTemplate
Constants ¶
const ( StatusDraft = workflow.StatusDraft StatusInReview = workflow.StatusInReview StatusReturned = workflow.StatusReturned StatusApproved = workflow.StatusApproved StatusRejectedClosed = workflow.StatusRejectedClosed )
Application status values.
const ( ReturnModeStrict = workflow.ReturnModeStrict ReturnModeDirect = workflow.ReturnModeDirect )
Return modes.
const ( ReviewTypeSingle = workflow.ReviewTypeSingle ReviewTypeAll = workflow.ReviewTypeAll )
Review types.
const ( ActionSubmit = workflow.ActionSubmit ActionApprove = workflow.ActionApprove ActionReturn = workflow.ActionReturn ActionRejectClose = workflow.ActionRejectClose )
Review log actions.
const ModuleName = "WorkflowModule"
Variables ¶
var ( ErrInvalidStatus = workflow.ErrInvalidStatus ErrNoPermission = workflow.ErrNoPermission ErrCommentRequired = workflow.ErrCommentRequired ErrTemplateEmpty = workflow.ErrTemplateEmpty ErrTemplateMismatch = workflow.ErrTemplateMismatch ErrAlreadyApproved = workflow.ErrAlreadyApproved ErrInvalidTemplate = workflow.ErrInvalidTemplate ErrStaleReturnStage = workflow.ErrStaleReturnStage ErrNotFound = workflow.ErrNotFound )
Engine and store errors.
var ErrNotReady = errors.New("workflowmodule: manager has no store yet (called before OnStart)")
ErrNotReady is returned by manager methods called before the module's OnStart hook has attached a Store. Inject the manager via Fx and use it from your own module's OnStart or later — never from InitDefaultConfigs or other pre-start code paths.
Functions ¶
func Module ¶
Module returns the Fx option that registers the workflow module under scope. The manager is exported as a named dependency (`name:"<scope>"`) so other Method-2 modules can inject it.
Pass WithDatabaseName to pick a specific named database.DatabaseConnector when the host app registers more than one.
Types ¶
type Application ¶
type Application = workflow.Application
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.
type ApproverResolver ¶
type ApproverResolver = workflow.ApproverResolver
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.
type ApproverResolverFunc ¶
type ApproverResolverFunc = workflow.ApproverResolverFunc
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.
type Option ¶
type Option func(*options)
Option configures the workflow module at registration time.
func WithDatabaseName ¶
WithDatabaseName selects which named database.DatabaseConnector this module should consume. The name must match the one used on the provider, e.g.
fx.Provide(fx.Annotated{Name: "workflow_db", Target: func() database.DatabaseConnector { ... }})
workflowmodule.Module("workflow", workflowmodule.WithDatabaseName("workflow_db"))
Leave unset to inject the unnamed connector (the default and only mode supported by common-modules' built-in sqlite/postgres connectors out of the box).
type Params ¶
type Params struct {
weedbox.Params
Database database.DatabaseConnector
}
Params declares the module's Fx dependencies. The database is injected as the common-modules interface so any connector (sqlite, postgres, ...) works.
type ReviewLog ¶
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.
type WorkflowManager ¶
type WorkflowManager struct {
// contains filtered or unexported fields
}
WorkflowManager is the user-facing handle for the workflow module. It owns the engine, the GORM-backed store, and the service that ties them together.
Concurrency: all exported methods are safe for concurrent use after OnStart. SetResolver may be called before or after OnStart; subsequent operations see the new resolver immediately because the engine pointer never changes.
func (*WorkflowManager) Approve ¶
func (m *WorkflowManager) Approve(ctx context.Context, applicationID, operatorID string) (workflow.Application, workflow.ReviewLog, error)
Approve records a stage approval, advancing the workflow when conditions are met.
func (*WorkflowManager) CreateDraft ¶
func (m *WorkflowManager) CreateDraft(ctx context.Context, app workflow.Application) error
CreateDraft persists a new application in Draft status.
func (*WorkflowManager) Engine ¶
func (m *WorkflowManager) Engine() *workflow.WorkflowEngine
Engine returns the underlying workflow engine. Use this for permission queries (CanView, CanReview, CanEditForm, CanResubmit).
func (*WorkflowManager) GetApplication ¶
func (m *WorkflowManager) GetApplication(ctx context.Context, applicationID string) (workflow.Application, error)
GetApplication loads an application snapshot.
func (*WorkflowManager) GetTemplate ¶
func (m *WorkflowManager) GetTemplate(ctx context.Context, templateID string) (workflow.WorkflowTemplate, error)
GetTemplate fetches a template definition by ID.
func (*WorkflowManager) ListLogs ¶
func (m *WorkflowManager) ListLogs(ctx context.Context, applicationID string) ([]workflow.ReviewLog, error)
ListLogs returns the chronological review log for an application.
func (*WorkflowManager) RejectClose ¶
func (m *WorkflowManager) RejectClose(ctx context.Context, applicationID, operatorID, comment string) (workflow.Application, workflow.ReviewLog, error)
RejectClose terminally closes the application with a required comment.
func (*WorkflowManager) Resubmit ¶
func (m *WorkflowManager) Resubmit(ctx context.Context, applicationID string) (workflow.Application, workflow.ReviewLog, error)
Resubmit puts a Returned application back into the review queue.
func (*WorkflowManager) Return ¶
func (m *WorkflowManager) Return(ctx context.Context, applicationID, operatorID, comment string) (workflow.Application, workflow.ReviewLog, error)
Return sends the application back to the owner with a required comment.
func (*WorkflowManager) SaveTemplate ¶
func (m *WorkflowManager) SaveTemplate(ctx context.Context, tpl workflow.WorkflowTemplate) error
SaveTemplate persists a template and reflows every in-flight application bound to it. See workflow.Service.SaveTemplate for reflow semantics.
func (*WorkflowManager) Service ¶
func (m *WorkflowManager) Service() *workflow.Service
Service returns the workflow.Service that ties engine and store together. Prefer the forwarding methods below for everyday use.
func (*WorkflowManager) SetResolver ¶
func (m *WorkflowManager) SetResolver(r workflow.ApproverResolver)
SetResolver installs a custom approver resolver on the engine. Calling this after the module has accepted live traffic is allowed but caller-coordinated: changing the resolver mid-round can affect ALL-stage approval counting.
func (*WorkflowManager) Store ¶
func (m *WorkflowManager) Store() *gormstore.Store
Store returns the GORM-backed store. Use this for low-level reads (template listing, log queries) or when you need to share the transaction with your own code via Store.Transact.
type WorkflowModule ¶
WorkflowModule is the weedbox module wrapper. The actual user-facing API lives on the embedded WorkflowManager.
func (*WorkflowModule) InitDefaultConfigs ¶
func (m *WorkflowModule) InitDefaultConfigs()
InitDefaultConfigs registers Viper defaults for this module's scope.
func (*WorkflowModule) Manager ¶
func (m *WorkflowModule) Manager() *WorkflowManager
Manager returns the WorkflowManager owned by this module.
type WorkflowStage ¶
type WorkflowStage = workflow.WorkflowStage
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.
type WorkflowTemplate ¶
type WorkflowTemplate = workflow.WorkflowTemplate
Re-exported domain types so callers can depend on this module alone, without also importing github.com/weedbox/workflow directly.