expense

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: 9 Imported by: 2

README

Expense

This sample workflow process an expense request. The key part of this sample is to show how to complete an activity asynchronously.

Sample Description

  • Create a new expense report.
  • Wait for the expense report to be approved. This could take an arbitrary amount of time. So the activity's Execute method has to return before it is actually approved. This is done by returning a special error so the framework knows the activity is not completed yet.
    • When the expense is approved (or rejected), somewhere in the world needs to be notified, and it will need to call client.CompleteActivity() to tell Temporal service that that activity is now completed. In this sample case, the dummy server do this job. In real world, you will need to register some listener to the expense system or you will need to have your own pulling agent to check for the expense status periodic.
  • After the wait activity is completed, it did the payment for the expense (dummy step in this sample case).

This sample rely on an a dummy expense server to work.

Steps To Run Sample

  • You need a Temporal service running. README.md for more details.
  • Start the dummy server
go run expense/server/main.go
  • Start workflow and activity workers
go run expense/worker/main.go
  • Start expanse workflow execution
go run expense/starter/main.go
  • When you see the console print out the expense is created, go to localhost:8099/list to approve the expense.
  • You should see the workflow complete after you approve the expense. You can also reject the expense.
  • If you see the workflow failed, try to change to a different port number in dummy.go and workflow.go. Then rerun everything.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateExpenseActivity

func CreateExpenseActivity(ctx context.Context, expenseID string) error

func PaymentActivity

func PaymentActivity(ctx context.Context, expenseID string) error

func SampleExpenseWorkflow

func SampleExpenseWorkflow(ctx workflow.Context, expenseID string) (result string, err error)

SampleExpenseWorkflow workflow definition

func WaitForDecisionActivity

func WaitForDecisionActivity(ctx context.Context, expenseID string) (string, error)

waitForDecisionActivity waits for the expense decision. This activity will complete asynchronously. When this method returns error activity.ErrResultPending, the Temporal Go SDK recognize this error, and won't mark this activity as failed or completed. The Temporal server will wait until Client.CompleteActivity() is called or timeout happened whichever happen first. In this sample case, the CompleteActivity() method is called by our dummy expense server when the expense is approved.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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