recovery

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: Apache-2.0 Imports: 15 Imported by: 4

README

Recovery Sample

This sample implements a RecoveryWorkflow which is designed to restart all TripWorkflow executions which are currently outstanding and replay all signals from previous run. This is useful where a bad code change is rolled out which causes workflows to get stuck or state is corrupted.

Steps to run this sample

  1. Run the following command to start worker
go run recovery/worker/main.go
  1. Run the following command to start trip workflow
go run recovery/starter/main.go
  1. Run the following command to query trip workflow
go run recovery/query/main.go
  1. Run the following command to send signal to trip workflow
go run recovery/signal/main.go -s '{"ID": "Trip1", "Total": 10}'
  1. Run the following command to start recovery workflow
go run recovery/starter/main.go -w recovery_workflow -wt recoveryworkflow -i '{"Type": "TripWorkflow", "Concurrency": 2}'

Documentation

Index

Constants

View Source
const (
	// TripSignalName is the signal name for trip completion event
	TripSignalName = "trip_event"

	// QueryName is the query type name
	QueryName = "counter"
)

Variables

View Source
var (
	// ErrClientNotFound when client is not found on context
	ErrClientNotFound = errors.New("failed to retrieve client from context")
	// ErrExecutionCacheNotFound when executions cache is not found on context
	ErrExecutionCacheNotFound = errors.New("failed to retrieve cache from context")
)
View Source
var HostID = "recovery_" + uuid.New()

HostID - Use a new uuid just for demo so we can run 2 host specific activity workers on same machine. In real world case, you would use a hostname or ip address as HostID.

Functions

func RecoverExecutions

func RecoverExecutions(ctx context.Context, key string, startIndex, batchSize int) error

func RecoverWorkflow

func RecoverWorkflow(ctx workflow.Context, params Params) error

RecoverWorkflow is the workflow implementation to recover TripWorkflow executions

func TripWorkflow

func TripWorkflow(ctx workflow.Context, state UserState) error

TripWorkflow to keep track of total trip count for a user It waits on a TripEvent signal and increments a counter on each signal received by this workflow Trip count is managed as workflow state and passed to new run after 10 signals received by each execution

Types

type ClientKey

type ClientKey int

ClientKey is the key for lookup

const (
	// TemporalClientKey for retrieving client from context
	TemporalClientKey ClientKey = iota
	// WorkflowExecutionCacheKey for retrieving executions cache from context
	WorkflowExecutionCacheKey
)

type ListOpenExecutionsResult

type ListOpenExecutionsResult struct {
	ID     string
	Count  int
	HostID string
}

ListOpenExecutionsResult is the result returned from listOpenExecutions activity

func ListOpenExecutions

func ListOpenExecutions(ctx context.Context, workflowType string) (*ListOpenExecutionsResult, error)

type Params

type Params struct {
	ID          string
	Type        string
	Concurrency int
}

Params is the input parameters to RecoveryWorkflow

type RestartParams

type RestartParams struct {
	Options client.StartWorkflowOptions
	State   UserState
}

RestartParams are parameters extracted from StartWorkflowExecution history event

type SignalParams

type SignalParams struct {
	Name string
	Data TripEvent
}

SignalParams are the parameters extracted from SignalWorkflowExecution history event

type TripEvent

type TripEvent struct {
	ID    string
	Total int
}

TripEvent passed in as signal to TripWorkflow

type UserState

type UserState struct {
	TripCounter int
}

UserState kept within workflow and passed from one run to another on ContinueAsNew

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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