refactor(approvals): judgement's change-request rules route an approval, and without a connector it goes to the channels (#1985)
This commit is contained in:
2 files changed
+11
-29
No files matched your search
@@ -206,23 +206,21 @@ type Module struct {
|
|||||||
func NewModule(db *sqlx.DB, log *slog.Logger, orgID string, tell Delivery, wake Signaller, classes Classes, policy Policy, people People) *Module {
|
func NewModule(db *sqlx.DB, log *slog.Logger, orgID string, tell Delivery, wake Signaller, classes Classes, policy Policy, people People) *Module {
|
||||||
return &Module{
|
return &Module{
|
||||||
orgID: orgID, store: store.New(db), tell: tell, wake: wake, classes: classes, policy: policy, people: people,
|
orgID: orgID, store: store.New(db), tell: tell, wake: wake, classes: classes, policy: policy, people: people,
|
||||||
changes: NoChangeRequests{}, log: log, now: time.Now,
|
log: log, now: time.Now,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask records a request for d and puts it to the first step of path. It runs
|
// Ask records a request for d and puts it to the first step of path. It runs
|
||||||
// out for good when the last step does. Asking again for the same run and key
|
// out for good when the last step does. Asking again for the same run and key
|
||||||
// returns the request that stands, so a replayed step asks once. An action the
|
// returns the request that stands, so a replayed step asks once. An action
|
||||||
// change-request rules pick goes through a change request, and every other one
|
// judgement's change-request rules pick goes through a change request when a
|
||||||
// through the approvers' channels.
|
// change-request connector is installed, and every other one through the
|
||||||
|
// approvers' channels.
|
||||||
func (m *Module) Ask(ctx context.Context, runID uuid.UUID, key string, d judgement.Decision, path []governance.PathStep) (Request, error) {
|
func (m *Module) Ask(ctx context.Context, runID uuid.UUID, key string, d judgement.Decision, path []governance.PathStep) (Request, error) {
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
return Request{}, ErrNoPath
|
return Request{}, ErrNoPath
|
||||||
}
|
}
|
||||||
changeRequest, err := m.changes.Needed(ctx, d)
|
changeRequest := d.ChangeRequest && m.changes != nil
|
||||||
if err != nil {
|
|
||||||
return Request{}, fmt.Errorf("route approval: %w", err)
|
|
||||||
}
|
|
||||||
now := m.now().UTC()
|
now := m.now().UTC()
|
||||||
var total time.Duration
|
var total time.Duration
|
||||||
for _, st := range path {
|
for _, st := range path {
|
||||||
|
|||||||
@@ -10,16 +10,11 @@ import (
|
|||||||
|
|
||||||
"github.com/samcharles93/archie-core/modules/deliveries"
|
"github.com/samcharles93/archie-core/modules/deliveries"
|
||||||
"github.com/samcharles93/archie-core/modules/governance"
|
"github.com/samcharles93/archie-core/modules/governance"
|
||||||
"github.com/samcharles93/archie-core/modules/judgement"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChangeRequests is the seam between approval routing and a change-request
|
// ChangeRequests is a change-request connector. Judgement's change-request
|
||||||
// connector. Routing asks one question of an action, whether it needs a change
|
// rules decide which held actions need one; this opens and withdraws them.
|
||||||
// request; every action that doesn't goes to the approvers' channels. The
|
|
||||||
// rules that answer it are deterministic and run after the guards.
|
|
||||||
type ChangeRequests interface {
|
type ChangeRequests interface {
|
||||||
// Needed reports whether d goes through a change request.
|
|
||||||
Needed(ctx context.Context, d judgement.Decision) (bool, error)
|
|
||||||
// Open raises the change request for r. It may be called again for the same
|
// Open raises the change request for r. It may be called again for the same
|
||||||
// request and must not open a second one.
|
// request and must not open a second one.
|
||||||
Open(ctx context.Context, r Request) error
|
Open(ctx context.Context, r Request) error
|
||||||
@@ -27,20 +22,9 @@ type ChangeRequests interface {
|
|||||||
Withdraw(ctx context.Context, r Request) error
|
Withdraw(ctx context.Context, r Request) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoChangeRequests is the routing while no change-request connector exists:
|
// UseChangeRequests makes the module open the change requests judgement asks
|
||||||
// no action needs one, so there is nothing to open or withdraw.
|
// for through c. Without one, those approvals go to the approvers' channels,
|
||||||
type NoChangeRequests struct{}
|
// so a rule never strands a request where nobody can answer it.
|
||||||
|
|
||||||
// Needed reports false.
|
|
||||||
func (NoChangeRequests) Needed(context.Context, judgement.Decision) (bool, error) { return false, nil }
|
|
||||||
|
|
||||||
// Open does nothing.
|
|
||||||
func (NoChangeRequests) Open(context.Context, Request) error { return nil }
|
|
||||||
|
|
||||||
// Withdraw does nothing.
|
|
||||||
func (NoChangeRequests) Withdraw(context.Context, Request) error { return nil }
|
|
||||||
|
|
||||||
// UseChangeRequests makes the module route approvals through c.
|
|
||||||
func (m *Module) UseChangeRequests(c ChangeRequests) { m.changes = c }
|
func (m *Module) UseChangeRequests(c ChangeRequests) { m.changes = c }
|
||||||
|
|
||||||
// Escalate passes a pending request to step n of its path, telling every
|
// Escalate passes a pending request to step n of its path, telling every
|
||||||
|
|||||||
Reference in new issue
Block a user