temporal

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusRunning    = "Running"
	StatusCompleted  = "Completed"
	StatusFailed     = "Failed"
	StatusCanceled   = "Canceled"
	StatusTerminated = "Terminated"
	StatusTimedOut   = "TimedOut"
	StatusUnknown    = "Unknown"
)

WorkflowStatus constants match the UI display strings.

View Source
const (
	NamespaceStateActive     = "Active"
	NamespaceStateDeprecated = "Deprecated"
	NamespaceStateDeleted    = "Deleted"
	NamespaceStateUnknown    = "Unknown"
)

NamespaceState constants.

View Source
const (
	TaskQueueTypeWorkflow = "Workflow"
	TaskQueueTypeActivity = "Activity"
)

TaskQueueType constants.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration for display.

func MapNamespaceState

func MapNamespaceState(state enums.NamespaceState) string

MapNamespaceState converts a Temporal SDK namespace state to a UI-friendly string.

func MapTaskQueueType

func MapTaskQueueType(tqType enums.TaskQueueType) string

MapTaskQueueType converts a Temporal SDK task queue type to a UI-friendly string.

func MapWorkflowStatus

func MapWorkflowStatus(status enums.WorkflowExecutionStatus) string

MapWorkflowStatus converts a Temporal SDK workflow execution status to a UI-friendly string.

func RegisterTemporalStatuses

func RegisterTemporalStatuses()

RegisterTemporalStatuses registers Temporal-specific statuses with jig's theme system. Uses dynamic colors that update when theme changes.

Types

type BatchResult

type BatchResult struct {
	WorkflowID string
	RunID      string
	Success    bool
	Error      string
}

BatchResult represents the result of a batch operation on a single workflow.

type Client

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

Client implements the Provider interface using the Temporal SDK.

func NewClient

func NewClient(ctx context.Context, connConfig ConnectionConfig) (*Client, error)

NewClient creates a new Temporal SDK client with the given configuration.

func (*Client) CancelWorkflow

func (c *Client) CancelWorkflow(ctx context.Context, namespace, workflowID, runID, reason string) error

CancelWorkflow requests graceful cancellation of a workflow execution.

func (*Client) CancelWorkflows

func (c *Client) CancelWorkflows(ctx context.Context, namespace string, workflows []WorkflowIdentifier) ([]BatchResult, error)

CancelWorkflows cancels multiple workflows and returns results for each.

func (*Client) CheckConnection

func (c *Client) CheckConnection(ctx context.Context) error

CheckConnection verifies the connection is still alive by making a lightweight API call.

func (*Client) Close

func (c *Client) Close() error

Close releases the client connection.

func (*Client) Config

func (c *Client) Config() ConnectionConfig

Config returns the connection configuration used by this client.

func (*Client) CreateNamespace

func (c *Client) CreateNamespace(ctx context.Context, req NamespaceCreateRequest) error

CreateNamespace registers a new namespace with the Temporal server.

func (*Client) DeleteNamespace

func (c *Client) DeleteNamespace(ctx context.Context, name string) error

DeleteNamespace permanently deletes a namespace.

func (*Client) DeleteSchedule

func (c *Client) DeleteSchedule(ctx context.Context, namespace, scheduleID string) error

DeleteSchedule permanently deletes a schedule.

func (*Client) DeleteWorkflow

func (c *Client) DeleteWorkflow(ctx context.Context, namespace, workflowID, runID string) error

DeleteWorkflow permanently deletes a workflow execution and its history.

func (*Client) DeprecateNamespace

func (c *Client) DeprecateNamespace(ctx context.Context, name string) error

DeprecateNamespace marks a namespace as deprecated (soft delete).

func (*Client) DescribeNamespace

func (c *Client) DescribeNamespace(ctx context.Context, name string) (*NamespaceDetail, error)

DescribeNamespace returns detailed information about a namespace.

func (*Client) DescribeTaskQueue

func (c *Client) DescribeTaskQueue(ctx context.Context, namespace, taskQueue string) (*TaskQueueInfo, []Poller, error)

DescribeTaskQueue returns task queue info and active pollers.

func (*Client) GetEnhancedWorkflowHistory

func (c *Client) GetEnhancedWorkflowHistory(ctx context.Context, namespace, workflowID, runID string) ([]EnhancedHistoryEvent, error)

GetEnhancedWorkflowHistory returns event history with relational data for tree/timeline views.

func (*Client) GetResetPoints

func (c *Client) GetResetPoints(ctx context.Context, namespace, workflowID, runID string) ([]ResetPoint, error)

GetResetPoints returns valid reset points for a workflow execution.

func (*Client) GetSchedule

func (c *Client) GetSchedule(ctx context.Context, namespace, scheduleID string) (*Schedule, error)

GetSchedule returns details for a specific schedule.

func (*Client) GetWorkflow

func (c *Client) GetWorkflow(ctx context.Context, namespace, workflowID, runID string) (*Workflow, error)

GetWorkflow returns details for a specific workflow execution.

func (*Client) GetWorkflowHistory

func (c *Client) GetWorkflowHistory(ctx context.Context, namespace, workflowID, runID string) ([]HistoryEvent, error)

GetWorkflowHistory returns the event history for a workflow execution.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client has an active connection.

func (*Client) ListNamespaces

func (c *Client) ListNamespaces(ctx context.Context) ([]Namespace, error)

ListNamespaces returns all namespaces visible to the client.

func (*Client) ListSchedules

func (c *Client) ListSchedules(ctx context.Context, namespace string, opts ListOptions) ([]Schedule, string, error)

ListSchedules returns all schedules in a namespace.

func (*Client) ListWorkflows

func (c *Client) ListWorkflows(ctx context.Context, namespace string, opts ListOptions) ([]Workflow, string, error)

ListWorkflows returns workflows for a namespace with optional filtering.

func (*Client) PauseSchedule

func (c *Client) PauseSchedule(ctx context.Context, namespace, scheduleID, reason string) error

PauseSchedule pauses a schedule.

func (*Client) QueryWorkflow

func (c *Client) QueryWorkflow(ctx context.Context, namespace, workflowID, runID, queryType string, args []byte) (*QueryResult, error)

QueryWorkflow executes a query against a running workflow and returns the result.

func (*Client) Reconnect

func (c *Client) Reconnect(ctx context.Context) error

Reconnect attempts to re-establish a connection to the Temporal server.

func (*Client) ReconnectWithConfig

func (c *Client) ReconnectWithConfig(ctx context.Context, newConfig ConnectionConfig) error

ReconnectWithConfig reconnects using a new configuration. This enables hot-swapping to a different Temporal server/namespace.

func (*Client) ResetWorkflow

func (c *Client) ResetWorkflow(ctx context.Context, namespace, workflowID, runID string, eventID int64, reason string) (string, error)

ResetWorkflow resets a workflow to a previous state, creating a new run.

func (*Client) SignalWithStartWorkflow

func (c *Client) SignalWithStartWorkflow(ctx context.Context, namespace string, req SignalWithStartRequest) (string, error)

SignalWithStartWorkflow starts a workflow if it doesn't exist and sends a signal to it.

func (*Client) SignalWorkflow

func (c *Client) SignalWorkflow(ctx context.Context, namespace, workflowID, runID, signalName string, input []byte) error

SignalWorkflow sends a signal to a running workflow execution.

func (*Client) TerminateWorkflow

func (c *Client) TerminateWorkflow(ctx context.Context, namespace, workflowID, runID, reason string) error

TerminateWorkflow forcefully terminates a workflow execution immediately.

func (*Client) TerminateWorkflows

func (c *Client) TerminateWorkflows(ctx context.Context, namespace string, workflows []WorkflowIdentifier, reason string) ([]BatchResult, error)

TerminateWorkflows terminates multiple workflows and returns results for each.

func (*Client) TriggerSchedule

func (c *Client) TriggerSchedule(ctx context.Context, namespace, scheduleID string) error

TriggerSchedule immediately triggers a scheduled workflow execution.

func (*Client) UnpauseSchedule

func (c *Client) UnpauseSchedule(ctx context.Context, namespace, scheduleID, reason string) error

UnpauseSchedule unpauses a schedule.

func (*Client) UpdateNamespace

func (c *Client) UpdateNamespace(ctx context.Context, req NamespaceUpdateRequest) error

UpdateNamespace modifies an existing namespace's configuration.

type ConnectionConfig

type ConnectionConfig struct {
	Address       string
	Namespace     string
	TLSCertPath   string
	TLSKeyPath    string
	TLSCAPath     string
	TLSServerName string
	TLSSkipVerify bool
}

ConnectionConfig holds Temporal server connection settings.

func DefaultConnectionConfig

func DefaultConnectionConfig() ConnectionConfig

DefaultConnectionConfig returns default connection settings.

type EnhancedHistoryEvent

type EnhancedHistoryEvent struct {
	ID      int64
	Type    string
	Time    time.Time
	Details string // Keep for backward compatibility

	// Relational fields for building event trees
	ScheduledEventID int64 // For Started/Completed events linking to Scheduled
	StartedEventID   int64 // For Completed events linking to Started
	InitiatedEventID int64 // For Child workflow events

	// Activity/Timer identity
	ActivityID   string
	ActivityType string
	TimerID      string

	// Child workflow info
	ChildWorkflowID   string
	ChildWorkflowType string

	// Timing for Gantt view
	EndTime *time.Time // Computed from linked completion event

	// Additional metadata
	Attempt   int32
	TaskQueue string
	Identity  string
	Failure   string
	Result    string
}

EnhancedHistoryEvent extends HistoryEvent with relational fields for tree/timeline views.

type EventGroupType

type EventGroupType int

EventGroupType represents the type of event grouping in the tree view.

const (
	GroupWorkflow EventGroupType = iota
	GroupWorkflowTask
	GroupActivity
	GroupTimer
	GroupChildWorkflow
	GroupSignal
	GroupMarker
	GroupOther
)

func (EventGroupType) String

func (g EventGroupType) String() string

String returns a human-readable name for the group type.

type EventTreeNode

type EventTreeNode struct {
	Name      string                  // Display name (e.g., "Activity: ValidateOrder")
	Type      EventGroupType          // Group type
	Status    string                  // Running, Completed, Failed, Canceled, TimedOut, Pending
	StartTime time.Time               // When this group started
	EndTime   *time.Time              // When this group ended (nil if still running)
	Duration  time.Duration           // Computed duration
	Events    []*EnhancedHistoryEvent // Raw events in this node
	Children  []*EventTreeNode        // Child nodes (for attempts/nested)
	Collapsed bool                    // UI state for expand/collapse
	Attempts  int                     // Number of retry attempts
}

EventTreeNode represents a node in the event tree.

func BuildEventTree

func BuildEventTree(events []EnhancedHistoryEvent) []*EventTreeNode

BuildEventTree constructs a tree from a flat list of enhanced history events.

func (*EventTreeNode) HasChildren

func (n *EventTreeNode) HasChildren() bool

HasChildren returns true if this node has children.

func (*EventTreeNode) IsLeaf

func (n *EventTreeNode) IsLeaf() bool

IsLeaf returns true if this node has no children.

type HistoryEvent

type HistoryEvent struct {
	ID      int64
	Type    string
	Time    time.Time
	Details string
}

HistoryEvent represents a workflow history event.

type ListOptions

type ListOptions struct {
	PageSize  int
	PageToken string
	Query     string // Visibility query (e.g., "WorkflowType='OrderWorkflow'")
}

ListOptions configures workflow list queries.

type Namespace

type Namespace struct {
	Name            string
	State           string
	RetentionPeriod string
	Description     string
	OwnerEmail      string
}

Namespace represents a Temporal namespace.

type NamespaceCreateRequest

type NamespaceCreateRequest struct {
	Name          string
	Description   string
	OwnerEmail    string
	RetentionDays int // Minimum 1 day
}

NamespaceCreateRequest contains parameters for creating a new namespace.

type NamespaceDetail

type NamespaceDetail struct {
	Namespace
	CreatedAt          time.Time
	UpdatedAt          time.Time
	HistoryArchival    string // Archival state + URI
	VisibilityArchival string // Archival state + URI
	ID                 string // Internal namespace UUID
	IsGlobalNamespace  bool
	FailoverVersion    int64
	Clusters           []string // Active clusters for multi-region
}

NamespaceDetail contains extended namespace information.

type NamespaceUpdateRequest

type NamespaceUpdateRequest struct {
	Name          string // Target namespace to update
	Description   string
	OwnerEmail    string
	RetentionDays int
}

NamespaceUpdateRequest contains parameters for updating an existing namespace.

type Poller

type Poller struct {
	Identity       string
	LastAccessTime time.Time
	TaskQueueType  string // "Workflow" or "Activity"
	RatePerSecond  float64
}

Poller represents a worker polling a task queue.

type Provider

type Provider interface {

	// ListNamespaces returns all namespaces visible to the client.
	ListNamespaces(ctx context.Context) ([]Namespace, error)

	// CreateNamespace registers a new namespace with the Temporal server.
	CreateNamespace(ctx context.Context, req NamespaceCreateRequest) error

	// DescribeNamespace returns detailed information about a namespace.
	DescribeNamespace(ctx context.Context, name string) (*NamespaceDetail, error)

	// UpdateNamespace modifies an existing namespace's configuration.
	UpdateNamespace(ctx context.Context, req NamespaceUpdateRequest) error

	// DeprecateNamespace marks a namespace as deprecated (soft delete).
	// Deprecated namespaces prevent new workflow executions but allow existing ones to complete.
	DeprecateNamespace(ctx context.Context, name string) error

	// DeleteNamespace permanently deletes a namespace.
	// The namespace must be deprecated first before it can be deleted.
	DeleteNamespace(ctx context.Context, name string) error

	// ListWorkflows returns workflows for a namespace with optional filtering.
	ListWorkflows(ctx context.Context, namespace string, opts ListOptions) ([]Workflow, string, error)

	// GetWorkflow returns details for a specific workflow execution.
	GetWorkflow(ctx context.Context, namespace, workflowID, runID string) (*Workflow, error)

	// GetWorkflowHistory returns the event history for a workflow execution.
	GetWorkflowHistory(ctx context.Context, namespace, workflowID, runID string) ([]HistoryEvent, error)

	// GetEnhancedWorkflowHistory returns event history with relational data for tree/timeline views.
	GetEnhancedWorkflowHistory(ctx context.Context, namespace, workflowID, runID string) ([]EnhancedHistoryEvent, error)

	// DescribeTaskQueue returns task queue info and active pollers.
	DescribeTaskQueue(ctx context.Context, namespace, taskQueue string) (*TaskQueueInfo, []Poller, error)

	// Close releases any resources held by the provider.
	Close() error

	// IsConnected returns true if the provider has an active connection.
	IsConnected() bool

	// CheckConnection verifies the connection is still alive by making a lightweight API call.
	CheckConnection(ctx context.Context) error

	// Reconnect attempts to re-establish a connection to the Temporal server.
	// Returns an error if reconnection fails.
	Reconnect(ctx context.Context) error

	// ReconnectWithConfig reconnects using a new configuration.
	// This enables hot-swapping to a different Temporal server/namespace.
	ReconnectWithConfig(ctx context.Context, config ConnectionConfig) error

	// Config returns the connection configuration used by this provider.
	Config() ConnectionConfig

	// CancelWorkflow requests graceful cancellation of a workflow execution.
	// The workflow can handle the cancellation and perform cleanup.
	CancelWorkflow(ctx context.Context, namespace, workflowID, runID, reason string) error

	// TerminateWorkflow forcefully terminates a workflow execution immediately.
	// No cleanup code will run in the workflow.
	TerminateWorkflow(ctx context.Context, namespace, workflowID, runID, reason string) error

	// SignalWorkflow sends a signal to a running workflow execution.
	SignalWorkflow(ctx context.Context, namespace, workflowID, runID, signalName string, input []byte) error

	// SignalWithStartWorkflow starts a workflow if it doesn't exist and sends a signal to it.
	// Returns the run ID of the workflow.
	SignalWithStartWorkflow(ctx context.Context, namespace string, req SignalWithStartRequest) (string, error)

	// DeleteWorkflow permanently deletes a workflow execution and its history.
	DeleteWorkflow(ctx context.Context, namespace, workflowID, runID string) error

	// ResetWorkflow resets a workflow to a previous state, creating a new run.
	ResetWorkflow(ctx context.Context, namespace, workflowID, runID string, eventID int64, reason string) (string, error)

	// ListSchedules returns all schedules in a namespace.
	ListSchedules(ctx context.Context, namespace string, opts ListOptions) ([]Schedule, string, error)

	// GetSchedule returns details for a specific schedule.
	GetSchedule(ctx context.Context, namespace, scheduleID string) (*Schedule, error)

	// PauseSchedule pauses a schedule.
	PauseSchedule(ctx context.Context, namespace, scheduleID, reason string) error

	// UnpauseSchedule unpauses a schedule.
	UnpauseSchedule(ctx context.Context, namespace, scheduleID, reason string) error

	// TriggerSchedule immediately triggers a scheduled workflow execution.
	TriggerSchedule(ctx context.Context, namespace, scheduleID string) error

	// DeleteSchedule permanently deletes a schedule.
	DeleteSchedule(ctx context.Context, namespace, scheduleID string) error

	// QueryWorkflow executes a query against a running workflow and returns the result.
	// queryType is the name of the query handler (e.g., "__stack_trace" for built-in stack trace).
	// args is optional JSON-encoded arguments to pass to the query handler.
	QueryWorkflow(ctx context.Context, namespace, workflowID, runID, queryType string, args []byte) (*QueryResult, error)

	// CancelWorkflows cancels multiple workflows and returns results for each.
	CancelWorkflows(ctx context.Context, namespace string, workflows []WorkflowIdentifier) ([]BatchResult, error)

	// TerminateWorkflows terminates multiple workflows and returns results for each.
	TerminateWorkflows(ctx context.Context, namespace string, workflows []WorkflowIdentifier, reason string) ([]BatchResult, error)

	// GetResetPoints returns valid reset points for a workflow execution.
	GetResetPoints(ctx context.Context, namespace, workflowID, runID string) ([]ResetPoint, error)
}

Provider defines the interface for Temporal data access. This abstraction allows for different implementations (real SDK, mock, etc.)

type QueryResult

type QueryResult struct {
	QueryType string
	Result    string // JSON-formatted result
	Error     string // Error message if query failed
}

QueryResult represents the result of a workflow query.

type ResetPoint

type ResetPoint struct {
	EventID     int64
	EventType   string
	Timestamp   time.Time
	Description string // Human-readable description (e.g., "Activity 'ProcessPayment' failed")
	Reason      string // Why this is a valid reset point
}

ResetPoint represents a valid point to reset a workflow to.

type Schedule

type Schedule struct {
	ID            string
	Spec          string // Human-readable schedule specification
	WorkflowType  string
	WorkflowID    string // Base workflow ID
	TaskQueue     string
	Paused        bool
	Notes         string
	NextRunTime   *time.Time
	LastRunTime   *time.Time
	LastRunStatus string
	TotalActions  int64
	RecentActions int64 // Actions in the last 24h
	OverlapPolicy string
}

Schedule represents a Temporal schedule.

type SignalWithStartRequest

type SignalWithStartRequest struct {
	WorkflowID    string
	WorkflowType  string
	TaskQueue     string
	SignalName    string
	SignalInput   []byte // JSON-encoded signal input
	WorkflowInput []byte // JSON-encoded workflow input
}

SignalWithStartRequest contains parameters for starting a workflow with a signal.

type TaskQueueInfo

type TaskQueueInfo struct {
	Name        string
	Type        string // "Workflow" or "Activity"
	PollerCount int
	Backlog     int
}

TaskQueueInfo represents task queue status information.

type Workflow

type Workflow struct {
	ID        string
	RunID     string
	Type      string
	Status    string // "Running", "Completed", "Failed", "Canceled", "Terminated", "TimedOut"
	Namespace string
	TaskQueue string
	StartTime time.Time
	EndTime   *time.Time
	ParentID  *string
	Memo      map[string]string
	Input     string // JSON-formatted workflow input
	Output    string // JSON-formatted workflow result (or failure message)
}

Workflow represents a workflow execution.

type WorkflowIdentifier

type WorkflowIdentifier struct {
	WorkflowID string
	RunID      string
}

WorkflowIdentifier uniquely identifies a workflow execution.

Jump to

Keyboard shortcuts

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