lro

package
v0.5.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package lro contains an implementation of https://pkg.go.dev/google.golang.org/genproto/googleapis/longrunning#OperationsServer

Index

Constants

View Source
const (
	// TaskIDMetadataTag is the tag for the task ID in gRPC metadata.
	TaskIDMetadataTag = "taskID"

	// JobStartIndicator is a log line we use to identify when the job has been started.
	JobStartIndicator = "CreateAndRunLROJobWithID: Create and run LRO job with id %v"
)
View Source
const (

	// DefaultWaitOperationTimeOut is the timeout for WaitOperation.
	DefaultWaitOperationTimeOut = 1 * time.Hour
)

Variables

View Source
var CreateAndRunLROJobWithID = func(ctx context.Context, id, name string, lro *Server, call func(ctx context.Context) (proto.Message, error)) (*Job, error) {
	if id == "" {
		id = CreateJobID()
	}
	job := &Job{
		id:   id,
		name: name,
		call: call,
		lro:  lro,
	}

	return addAndStartJob(ctx, lro, job)
}

CreateAndRunLROJobWithID creates an LRO job that can be cancelled. The method passed in is the main part of the call, adding into the job set and then starting it. It uses the given lro job id as the id.

Functions

func BuildOperation

func BuildOperation(id string, done bool, result *anypb.Any, e error) *opspb.Operation

BuildOperation builds the operation response for this specific grpcstatus.

func CreateJobID

func CreateJobID() string

CreateJobID creates a new job id based on uuid.

func GetOperationData

func GetOperationData(id string, j job) *opspb.Operation

GetOperationData fills in the operation data for this specific job.

Types

type Job

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

Job represents a long running operation and its metadata.

func CreateAndRunLROJobWithContext

func CreateAndRunLROJobWithContext(ctx context.Context, name string, lro *Server, call func(ctx context.Context) (proto.Message, error)) (*Job, error)

CreateAndRunLROJobWithContext creates an LRO job that can be cancelled. The method passed in is the main part of the call, adding into the job set and then starting it. It pulls the job id from grpc context.

func (*Job) Cancel

func (j *Job) Cancel() error

Cancel cancels the job.

func (*Job) Delete

func (j *Job) Delete() error

Delete deletes the job. It's not implemented yet.

func (*Job) ID

func (j *Job) ID() string

ID returns the ID of the job.

func (*Job) IsDone

func (j *Job) IsDone() bool

IsDone returns whether the job is done.

func (*Job) Name

func (j *Job) Name() string

Name returns the name of the job.

func (*Job) Status

func (j *Job) Status() (bool, *anypb.Any, error)

Status gets the current status of the job, returning error or response on completion.

func (*Job) Wait

func (j *Job) Wait(timeout time.Duration) error

Wait waits for the job to complete or timeout.

type Server

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

Server is a gRPC based operation server which implements google/longrunning/operations.proto .

func NewServer

func NewServer(ctx context.Context) *Server

NewServer returns Long running operation server.

func (*Server) AddJob

func (s *Server) AddJob(id string, job job) error

AddJob adds a job into the server to be tracked.

func (*Server) CancelOperation

func (s *Server) CancelOperation(_ context.Context, request *opspb.CancelOperationRequest) (*emptypb.Empty, error)

CancelOperation cancels a long running operation. It is the implementation of CancelOperation in google/longrunning/operations.proto.

func (*Server) DeleteExpiredJobs

func (s *Server) DeleteExpiredJobs(ttlAfterDelete time.Duration, ttlAfterComplete time.Duration)

DeleteExpiredJobs deletes the jobs that are considered as expired.

func (*Server) DeleteOperation

func (s *Server) DeleteOperation(_ context.Context, request *opspb.DeleteOperationRequest) (*emptypb.Empty, error)

DeleteOperation is part of google/longrunning/operations.proto.

func (*Server) EndOperation

func (s *Server) EndOperation(id string, status string)

EndOperation records the result of the operation.

func (*Server) GetOperation

func (s *Server) GetOperation(_ context.Context, request *opspb.GetOperationRequest) (*opspb.Operation, error)

GetOperation gets the status of the LRO operation. It is the implementation of GetOperation in google/longrunning/operations.proto.

func (*Server) ListOperations

ListOperations is part of google/longrunning/operations.proto. It is not implemented fully yet.

func (*Server) WaitAndUnmarshalResult

func (s *Server) WaitAndUnmarshalResult(ctx context.Context, opName string, targetProto proto.Message) error

WaitAndUnmarshalResult waits until the operation with the opName finishes, and either populates the result or the error.

func (*Server) WaitOperation

func (s *Server) WaitOperation(_ context.Context, request *opspb.WaitOperationRequest) (*opspb.Operation, error)

WaitOperation is part of google/longrunning/operations.proto.

Jump to

Keyboard shortcuts

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