restartengine

package
v0.85.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package restartengine decides and executes dev-server restart/build behavior.

Keeping restart policy here prevents runloop and hook layers from duplicating process ordering and cancellation logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunLifecycleEventString

func RunLifecycleEventString(event RunLifecycleEvent) string

RunLifecycleEventString provides stable log labels for transition events.

func RunLifecycleStateString

func RunLifecycleStateString(state RunLifecycleState) string

RunLifecycleStateString provides stable log labels for states.

func TryEnqueueRestartRequest

func TryEnqueueRestartRequest(
	restartRequests chan RestartRequest,
	request RestartRequest,
) bool

TryEnqueueRestartRequest attempts non-blocking enqueue.

func ValidateLifecycleTransitionTable

func ValidateLifecycleTransitionTable() error

ValidateLifecycleTransitionTable runs simple consistency checks over transitions.

Types

type GoCompilationOrderingPolicy

type GoCompilationOrderingPolicy int

GoCompilationOrderingPolicy controls relative ordering of hook/build work.

const (
	// GoCompilationOrderingPolicyConcurrentWithBuildHooks allows parallel go build + hooks.
	GoCompilationOrderingPolicyConcurrentWithBuildHooks GoCompilationOrderingPolicy = iota
	// GoCompilationOrderingPolicyAfterBuildHooks serializes go build after hooks.
	GoCompilationOrderingPolicyAfterBuildHooks
	// GoCompilationOrderingPolicyNotRequested disables go compilation.
	GoCompilationOrderingPolicyNotRequested
)

type RestartIntentAccumulator

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

RestartIntentAccumulator coalesces restart intents without losing upgrades.

func NewRestartIntentAccumulator

func NewRestartIntentAccumulator(
	restartRequests chan RestartRequest,
) *RestartIntentAccumulator

NewRestartIntentAccumulator creates an intent accumulator around request channel.

func (*RestartIntentAccumulator) ConsumeBlocking

func (accumulator *RestartIntentAccumulator) ConsumeBlocking() RestartRequest

ConsumeBlocking blocks until a restart request becomes available.

func (*RestartIntentAccumulator) ConsumePending

func (accumulator *RestartIntentAccumulator) ConsumePending() (RestartRequest, bool)

ConsumePending returns pending request if present and clears pending state.

func (*RestartIntentAccumulator) HasQueuedOrPendingRequest

func (accumulator *RestartIntentAccumulator) HasQueuedOrPendingRequest() bool

HasQueuedOrPendingRequest reports whether any restart request is currently queued.

func (*RestartIntentAccumulator) Queue

func (accumulator *RestartIntentAccumulator) Queue(
	incomingRequest RestartRequest,
)

Queue queues restart request, coalescing when queue is already full.

type RestartRequest

type RestartRequest struct {
	RecompileGo     bool
	IsConfigRestart bool
}

RestartRequest is one queued restart intent from watcher or lifecycle actions.

func MergeRestartRequests

func MergeRestartRequests(
	pendingRequest RestartRequest,
	incomingRequest RestartRequest,
) RestartRequest

MergeRestartRequests merges restart intents with strict upgrade semantics.

func NormalizeRestartRequest

func NormalizeRestartRequest(request RestartRequest) RestartRequest

NormalizeRestartRequest normalizes an incoming restart request.

func ResolveQueuedRestartRequest

func ResolveQueuedRestartRequest(
	pendingRequest *RestartRequest,
	incomingRequest RestartRequest,
) RestartRequest

ResolveQueuedRestartRequest resolves incoming request against optional pending one.

func TryDequeueRestartRequest

func TryDequeueRestartRequest(
	restartRequests chan RestartRequest,
) (RestartRequest, bool)

TryDequeueRestartRequest attempts non-blocking dequeue.

type RunBuildExecutionOrderingDecision

type RunBuildExecutionOrderingDecision struct {
	ShouldCompileGo bool
	OrderingPolicy  GoCompilationOrderingPolicy
}

RunBuildExecutionOrderingDecision determines one run-build execution strategy.

func DeriveRunBuildExecutionOrderingDecision

func DeriveRunBuildExecutionOrderingDecision(
	shouldRecompileGo bool,
	sequentialGoBuild bool,
) RunBuildExecutionOrderingDecision

DeriveRunBuildExecutionOrderingDecision derives build ordering from intent/config.

type RunCycleScope

type RunCycleScope struct {
	CycleID          uint64
	ExecutionContext context.Context
	// contains filtered or unexported fields
}

RunCycleScope owns cancellation and async work joining for one cycle.

func NewRunCycleScope

func NewRunCycleScope(cycleID uint64) *RunCycleScope

NewRunCycleScope creates one cycle scope with cancelable context.

func (*RunCycleScope) Cancel

func (runCycleScope *RunCycleScope) Cancel()

Cancel requests cancellation for cycle-scoped work.

func (*RunCycleScope) CancelAndWait

func (runCycleScope *RunCycleScope) CancelAndWait()

CancelAndWait cancels and then waits for all scoped work.

func (*RunCycleScope) LaunchAsyncWork

func (runCycleScope *RunCycleScope) LaunchAsyncWork(
	runAsyncWork func(context.Context),
)

LaunchAsyncWork launches one asynchronous unit under cycle context.

func (*RunCycleScope) Wait

func (runCycleScope *RunCycleScope) Wait()

Wait blocks until all launched async work has completed.

type RunIntent

type RunIntent struct {
	RecompileGo     bool
	IsRebuild       bool
	IsConfigRestart bool
}

RunIntent is one cycle-level intent derived from restart request.

func DeriveRunIntentFromRestartRequest

func DeriveRunIntentFromRestartRequest(
	restartRequestForIntent RestartRequest,
) RunIntent

DeriveRunIntentFromRestartRequest derives run-cycle execution intent.

type RunLifecycleCommand

type RunLifecycleCommand int

RunLifecycleCommand identifies a concrete command implementation for state.

const (
	// RunLifecycleCommandPrepareCycle executes pre-cycle setup.
	RunLifecycleCommandPrepareCycle RunLifecycleCommand = iota
	// RunLifecycleCommandBuildCycle executes build-stage work.
	RunLifecycleCommandBuildCycle
	// RunLifecycleCommandAwaitBuildRetry waits for retry trigger.
	RunLifecycleCommandAwaitBuildRetry
	// RunLifecycleCommandStartRuntime starts runtime services.
	RunLifecycleCommandStartRuntime
	// RunLifecycleCommandAwaitRestartRequest blocks for restart request.
	RunLifecycleCommandAwaitRestartRequest
	// RunLifecycleCommandCleanupForNextCycle executes restart cleanup.
	RunLifecycleCommandCleanupForNextCycle
)

func DeriveRunLifecycleCommandForState

func DeriveRunLifecycleCommandForState(
	currentRunLifecycleState RunLifecycleState,
) (RunLifecycleCommand, error)

DeriveRunLifecycleCommandForState maps lifecycle state to command.

type RunLifecycleCommandInput

type RunLifecycleCommandInput struct {
	CurrentCycleID uint64
	CurrentIntent  RunIntent
	FirstRun       bool
}

RunLifecycleCommandInput carries cycle-level command dependencies.

type RunLifecycleCommandResult

type RunLifecycleCommandResult struct {
	RunLifecycleEvent RunLifecycleEvent
	NextRunIntent     RunIntent
}

RunLifecycleCommandResult carries event and next-intent from command execution.

type RunLifecycleEvent

type RunLifecycleEvent int

RunLifecycleEvent identifies one transition trigger.

const (
	// RunLifecycleEventCyclePrepared transitions preparation to build.
	RunLifecycleEventCyclePrepared RunLifecycleEvent = iota
	// RunLifecycleEventBuildSucceeded transitions build to runtime start.
	RunLifecycleEventBuildSucceeded
	// RunLifecycleEventBuildFailed transitions build to retry wait.
	RunLifecycleEventBuildFailed
	// RunLifecycleEventBuildRetryRestartReceived transitions retry wait to cleanup.
	RunLifecycleEventBuildRetryRestartReceived
	// RunLifecycleEventRuntimeStarted transitions runtime-start to restart wait.
	RunLifecycleEventRuntimeStarted
	// RunLifecycleEventRestartRequestReceived transitions restart wait to cleanup.
	RunLifecycleEventRestartRequestReceived
	// RunLifecycleEventCleanupCompleted transitions cleanup to prepare cycle.
	RunLifecycleEventCleanupCompleted
)

type RunLifecycleState

type RunLifecycleState int

RunLifecycleState identifies one run-loop state.

const (
	// RunLifecycleStatePreparingCycle performs cleanup and cycle setup.
	RunLifecycleStatePreparingCycle RunLifecycleState = iota
	// RunLifecycleStateBuildingCycle performs one build for current intent.
	RunLifecycleStateBuildingCycle
	// RunLifecycleStateAwaitingBuildRetry waits for file changes after build failure.
	RunLifecycleStateAwaitingBuildRetry
	// RunLifecycleStateStartingRuntime starts app/vite/runtime watchers.
	RunLifecycleStateStartingRuntime
	// RunLifecycleStateAwaitingRestart waits for explicit restart requests.
	RunLifecycleStateAwaitingRestart
	// RunLifecycleStateCleaningUpForNextCycle performs stop/cancel transitions.
	RunLifecycleStateCleaningUpForNextCycle
)

func DeriveRunLifecycleStateAfterEvent

func DeriveRunLifecycleStateAfterEvent(
	currentRunLifecycleState RunLifecycleState,
	runLifecycleEventForTransition RunLifecycleEvent,
) (RunLifecycleState, error)

DeriveRunLifecycleStateAfterEvent applies pure transition logic.

func TransitionRunLifecycleState

func TransitionRunLifecycleState(
	transitionLogger TransitionLogger,
	currentRunLifecycleState RunLifecycleState,
	runLifecycleEventForTransition RunLifecycleEvent,
	currentLifecycleCycleID uint64,
) (RunLifecycleState, error)

TransitionRunLifecycleState applies one transition and optionally logs it.

type TransitionLogger

type TransitionLogger interface {
	Info(string, ...any)
}

TransitionLogger is the minimal logging contract for lifecycle transitions.

Jump to

Keyboard shortcuts

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