taskflow

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package taskflow offers task flow operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

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

Task defines the task

type TaskFlow

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

TaskFlow defines the task flow

func NewTaskFlow

func NewTaskFlow(ctx context.Context, name string) *TaskFlow

NewTaskFlow create a task flow

func (*TaskFlow) AddTask

func (p *TaskFlow) AddTask(name string, run TaskRunFunc, revert TaskRevertFunc)

AddTask add a task to task flow

func (*TaskFlow) AddTaskWithOutRevert

func (p *TaskFlow) AddTaskWithOutRevert(run TaskWithoutRevert) *TaskFlow

AddTaskWithOutRevert be used when the task does not need revert function

func (*TaskFlow) GetResult

func (p *TaskFlow) GetResult() map[string]interface{}

GetResult get tasks execution results in the task flow

func (*TaskFlow) Revert

func (p *TaskFlow) Revert()

Revert revert tasks in the task flow with revert function

func (*TaskFlow) Run

func (p *TaskFlow) Run(params map[string]interface{}) (map[string]interface{}, error)

Run execute tasks in the task flow

func (*TaskFlow) RunWithOutRevert

func (p *TaskFlow) RunWithOutRevert(params map[string]interface{}) error

RunWithOutRevert run task without revert function and return only error

type TaskRevertFunc

type TaskRevertFunc func(ctx context.Context, result map[string]interface{}) error

TaskRevertFunc revert task

type TaskRunFunc

type TaskRunFunc func(ctx context.Context, params map[string]interface{}, result map[string]interface{}) (map[string]interface{}, error)

TaskRunFunc run task

type TaskWithoutRevert

type TaskWithoutRevert func(ctx context.Context, params map[string]interface{}) error

TaskWithoutRevert run task without revert

type Transaction

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

Transaction implements a TCC (Try Confirm Cancel) pattern.

func NewTransaction

func NewTransaction() *Transaction

NewTransaction instantiate a new transaction.

func (*Transaction) Commit

func (t *Transaction) Commit() error

Commit executes the Transaction steps and returns error if any one step returns error.

func (*Transaction) Rollback

func (t *Transaction) Rollback()

Rollback executes the Transaction rollbacks.

func (*Transaction) Then

func (t *Transaction) Then(exec func() error, onRollback func()) *Transaction

Then adds a step to the steps chain, and returns the same Transaction,

Jump to

Keyboard shortcuts

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