github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/orchestration/handlers/cancel.go (about) 1 package handlers 2 3 import ( 4 "fmt" 5 "time" 6 7 orchestrationExt "github.com/kyma-project/kyma-environment-broker/common/orchestration" 8 "github.com/kyma-project/kyma-environment-broker/internal/storage" 9 "github.com/sirupsen/logrus" 10 ) 11 12 type Canceler struct { 13 orchestrations storage.Orchestrations 14 log logrus.FieldLogger 15 } 16 17 func NewCanceler(orchestrations storage.Orchestrations, logger logrus.FieldLogger) *Canceler { 18 return &Canceler{ 19 orchestrations: orchestrations, 20 log: logger, 21 } 22 } 23 24 // CancelForID cancels orchestration by ID 25 func (c *Canceler) CancelForID(orchestrationID string) error { 26 o, err := c.orchestrations.GetByID(orchestrationID) 27 if err != nil { 28 return fmt.Errorf("while getting orchestration: %w", err) 29 } 30 if o.IsFinished() || o.State == orchestrationExt.Canceling { 31 return nil 32 } 33 34 o.UpdatedAt = time.Now() 35 o.Description = "Orchestration was canceled" 36 o.State = orchestrationExt.Canceling 37 err = c.orchestrations.Update(*o) 38 if err != nil { 39 return fmt.Errorf("while updating orchestration: %w", err) 40 } 41 return nil 42 }