mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? This PR adds methods in workflow component to handle nexus events. ## Why? Migrating Nexus from HSM to CHASM ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) --- > [!NOTE] > **Medium Risk** > Touches the workflow-task completion path and CHASM workflow wiring (registry injection and history-event application), so misregistration or missing context could cause runtime command failures despite largely being additive/refactor changes. > > **Overview** > Adds CHASM `Workflow` helpers to *emit and apply* Nexus operation lifecycle events (started/completed/failed/canceled/timed-out), including consistent failure wrapping via `NexusOperationExecutionFailure`. > > Refactors CHASM workflow command/event registration by moving `workflowregistry` into `chasm/lib/workflow` as `Registry`, injecting it into CHASM context, and updating Nexus workflow command handlers to use `AddAndApplyHistoryEvent` so command-emitted history events immediately run their registered event definitions. Updates wiring/tests/callers across services to construct `NewLibrary(NewRegistry())` and use the new types/errors. > > <sup>Written by [Cursor Bugbot]() for commit 70936c6edabf0b96307738c28d60ac2adbcf8b83. This will update automatically on new commits. Configure [here]().</sup>
28 lines
1.4 KiB
Go
28 lines
1.4 KiB
Go
package workflow
|
|
|
|
import (
|
|
"errors"
|
|
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
historypb "go.temporal.io/api/history/v1"
|
|
"go.temporal.io/server/chasm"
|
|
)
|
|
|
|
// ErrEventNotCherryPickable should be returned by CherryPick if an event should not be cherry picked for whatever reason.
|
|
var ErrEventNotCherryPickable = errors.New("event not cherry pickable")
|
|
|
|
// EventDefinition is a definition for a history event for a given event type.
|
|
type EventDefinition interface {
|
|
Type() enumspb.EventType
|
|
// IsWorkflowTaskTrigger returns a boolean indicating whether this event type should trigger a workflow task.
|
|
IsWorkflowTaskTrigger() bool
|
|
// Apply a history event to the state machine. Triggered during replication and workflow reset.
|
|
Apply(ctx chasm.MutableContext, wf *Workflow, event *historypb.HistoryEvent) error
|
|
// CherryPick (a.k.a "reapply") an event from a different history branch.
|
|
// Implementations should apply the event to the machine state and return nil in case the event is cherry-pickable.
|
|
// Command events should never be cherry picked as we rely on the workflow to reschedule them.
|
|
// Return [ErrEventNotCherryPickable] to skip cherry picking. Any other error is considered fatal and will abort the
|
|
// cherry pick process.
|
|
CherryPick(ctx chasm.MutableContext, wf *Workflow, event *historypb.HistoryEvent, resetReapplyExcludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error
|
|
}
|