service

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFieldValidators

func RegisterFieldValidators(g *TaskMutationGate)

RegisterFieldValidators registers standard field validators with the gate. Each validator runs on both create and update operations.

Types

type AfterHook

type AfterHook func(ctx context.Context, old, new *task.Task) error

AfterHook runs after a successful mutation for side effects (e.g. trigger cascades). Hooks receive the context (with trigger depth), old and new task snapshots. Errors are logged but do not propagate — the original mutation is not affected.

type MutationValidator

type MutationValidator func(old, new *task.Task, allTasks []*task.Task) *Rejection

MutationValidator inspects a mutation and optionally rejects it. For create: old=nil, new=proposed task. For update: old=current persisted version (cloned), new=proposed version. For delete: old=task being deleted, new=nil.

type Rejection

type Rejection struct {
	Reason string
}

Rejection is returned by a validator to deny a mutation.

type RejectionError

type RejectionError struct {
	Rejections []Rejection
}

RejectionError holds one or more rejections from validators.

func (*RejectionError) Error

func (e *RejectionError) Error() string

type TaskMutationGate

type TaskMutationGate struct {
	// contains filtered or unexported fields
}

TaskMutationGate is the single gateway for all task mutations. All Create/Update/Delete/AddComment operations must go through this gate. Validators are registered per operation type and run before persistence. After-hooks run post-persist for side effects; their errors are logged, not propagated.

func BuildGate

func BuildGate() *TaskMutationGate

BuildGate creates a TaskMutationGate with standard field validators registered. Call SetStore() on the returned gate after store initialization.

func NewTaskMutationGate

func NewTaskMutationGate() *TaskMutationGate

NewTaskMutationGate creates a gate without a store. Call SetStore after store initialization. Validator registration is safe before SetStore — mutations are not.

func (*TaskMutationGate) AddComment

func (g *TaskMutationGate) AddComment(taskID string, comment task.Comment) error

AddComment adds a comment to a task. Returns an error if the task does not exist.

func (*TaskMutationGate) CreateTask

func (g *TaskMutationGate) CreateTask(ctx context.Context, t *task.Task) error

CreateTask validates the task, sets timestamps, persists it, and runs after-hooks.

func (*TaskMutationGate) DeleteTask

func (g *TaskMutationGate) DeleteTask(ctx context.Context, t *task.Task) error

DeleteTask validates, removes a task, and runs after-hooks. Receives the full task so delete validators can inspect it.

func (*TaskMutationGate) OnAfterCreate

func (g *TaskMutationGate) OnAfterCreate(h AfterHook)

OnAfterCreate registers a hook that runs after a successful CreateTask.

func (*TaskMutationGate) OnAfterDelete

func (g *TaskMutationGate) OnAfterDelete(h AfterHook)

OnAfterDelete registers a hook that runs after a successful DeleteTask.

func (*TaskMutationGate) OnAfterUpdate

func (g *TaskMutationGate) OnAfterUpdate(h AfterHook)

OnAfterUpdate registers a hook that runs after a successful UpdateTask.

func (*TaskMutationGate) OnCreate

func (g *TaskMutationGate) OnCreate(v MutationValidator)

OnCreate registers a validator that runs before CreateTask.

func (*TaskMutationGate) OnDelete

func (g *TaskMutationGate) OnDelete(v MutationValidator)

OnDelete registers a validator that runs before DeleteTask.

func (*TaskMutationGate) OnUpdate

func (g *TaskMutationGate) OnUpdate(v MutationValidator)

OnUpdate registers a validator that runs before UpdateTask.

func (*TaskMutationGate) ReadStore

func (g *TaskMutationGate) ReadStore() store.ReadStore

ReadStore returns the underlying store as a read-only interface.

func (*TaskMutationGate) SetStore

func (g *TaskMutationGate) SetStore(s store.Store)

SetStore wires the persistence layer into the gate.

func (*TaskMutationGate) UpdateTask

func (g *TaskMutationGate) UpdateTask(ctx context.Context, t *task.Task) error

UpdateTask validates the task, sets UpdatedAt, persists changes, and runs after-hooks.

type TimeTriggerEntry

type TimeTriggerEntry struct {
	Description string
	Trigger     *ruki.TimeTrigger
	Validated   *ruki.ValidatedTimeTrigger
}

TimeTriggerEntry holds a parsed time trigger and its description.

type TriggerEngine

type TriggerEngine struct {
	// contains filtered or unexported fields
}

TriggerEngine bridges parsed triggers with the mutation gate. Before-triggers become MutationValidators, after-triggers become AfterHooks.

func LoadAndRegisterTriggers

func LoadAndRegisterTriggers(gate *TaskMutationGate, schema ruki.Schema, userFunc func() string) (*TriggerEngine, int, error)

LoadAndRegisterTriggers loads trigger definitions from workflow.yaml, parses them, and registers them with the gate. Returns the engine (always non-nil), the number of triggers loaded, and any error. Callers can call StartScheduler on the engine without nil-checking — it early-returns on zero time triggers. Fails fast on parse errors — a bad trigger blocks startup.

func NewTriggerEngine

func NewTriggerEngine(triggers []triggerEntry, timeTriggers []TimeTriggerEntry, executor *ruki.TriggerExecutor) *TriggerEngine

NewTriggerEngine creates a TriggerEngine from parsed event and time triggers.

func (*TriggerEngine) RegisterWithGate

func (te *TriggerEngine) RegisterWithGate(gate *TaskMutationGate)

RegisterWithGate wires the triggers into the gate as validators and hooks.

func (*TriggerEngine) StartScheduler

func (te *TriggerEngine) StartScheduler(ctx context.Context)

StartScheduler launches a background goroutine for each time trigger. Each goroutine fires on a time.Ticker interval. Context cancellation stops all goroutines. Safe to call even when there are no time triggers — returns immediately.

func (*TriggerEngine) TimeTriggers

func (te *TriggerEngine) TimeTriggers() []TimeTriggerEntry

TimeTriggers returns the stored time trigger entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL