go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/worker/workflows/stabilize.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package workflows
     9  
    10  import (
    11  	"time"
    12  
    13  	"go.charczuk.com/projects/nodes/worker/activities"
    14  	"go.charczuk.com/sdk/uuid"
    15  	"go.temporal.io/sdk/temporal"
    16  	"go.temporal.io/sdk/workflow"
    17  )
    18  
    19  type StabilizeArgs struct {
    20  	UserID  uuid.UUID
    21  	GraphID uuid.UUID
    22  }
    23  
    24  type StabilizeResult struct {
    25  	StabilizationNum uint64 `json:"stabilization_num"`
    26  }
    27  
    28  func Stabilize(ctx workflow.Context, args StabilizeArgs) (output StabilizeResult, err error) {
    29  	ao := workflow.ActivityOptions{
    30  		StartToCloseTimeout:    60 * time.Second,  // this is bound, largely, by worker shutdown grace period
    31  		ScheduleToCloseTimeout: 120 * time.Second, // don't retry forever!
    32  		RetryPolicy: &temporal.RetryPolicy{
    33  			MaximumAttempts: 1, // do not attempt this multiple times!
    34  		},
    35  	}
    36  	ctx = workflow.WithActivityOptions(ctx, ao)
    37  	var result activities.StabilizeResult
    38  	if err = workflow.ExecuteActivity(ctx, new(activities.Activities).Stabilize, activities.StabilizeArgs{
    39  		GraphID: args.GraphID,
    40  		UserID:  args.UserID,
    41  	}).Get(ctx, &result); err != nil {
    42  		return
    43  	}
    44  	output.StabilizationNum = result.StabilizationNum
    45  	return
    46  }