fileprocessing

package
v0.0.0-...-94a9b73 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

This sample workflow demos a file processing process. The key part is to show how to use the session API.

The workflow first starts an activity to download a requested resource file from web and store it locally on the host where it runs the download activity. Then, the workflow will start more activities to process the downloaded resource file. The key part is the following activities have to be run on the same host as the initial downloading activity. This is achieved by using the session API.

Steps for using Session API:

  1. When starting worker, set EnableSessionWorker to true in workerOptions.
  2. In the workflow code, create a new session using the CreateSession() API
  so := &workflow.SessionOptions{
    CreationTimeout:  time.Minute,
    ExecutionTimeout: time.Minute,
  }
  sessionCtx, err := workflow.CreateSession(ctx, so)
  1. Use the returned sessionCtx or its child context to execute activities. These activities will be to scheduled on the same host.
  2. After all activities are executed, call CompleteSession().
  workflow.CompleteSession(sessionCtx)
  1. Check the inline document in workflow/session.go of the Go SDK repo for more advanced usage.

Steps to run this sample:

  1. You need a Temporal service running. See details in README.md
  2. Run the following command multiple times on different console window. This is to simulate running workers on multiple different machines.
go run fileprocessing/worker/main.go
  1. Run the following command to submit a start request for this fileprocessing workflow.
go run fileprocessing/starter/main.go

You should see that all activities for one particular workflow execution are scheduled to run on one console window.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SampleFileProcessingWorkflow

func SampleFileProcessingWorkflow(ctx workflow.Context, fileName string) (err error)

SampleFileProcessingWorkflow workflow definition

Types

type Activities

type Activities struct {
	BlobStore *BlobStore
}

func (*Activities) DownloadFileActivity

func (a *Activities) DownloadFileActivity(ctx context.Context, fileID string) (string, error)

func (*Activities) ProcessFileActivity

func (a *Activities) ProcessFileActivity(ctx context.Context, fileName string) (string, error)

func (*Activities) UploadFileActivity

func (a *Activities) UploadFileActivity(ctx context.Context, fileName string) error

type BlobStore

type BlobStore struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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