mirror of https://github.com/harness/drone.git
feat: [CDE-256]: Making gitspace delete async. (#2563)
* feat: [CDE-256]: Making gitspace delete async.pull/3545/head
parent
40ee05ca11
commit
98e5f7c498
|
@ -51,39 +51,43 @@ func (c *Controller) Delete(
|
||||||
instance, _ := c.gitspaceInstanceStore.FindLatestByGitspaceConfigID(ctx, gitspaceConfig.ID, gitspaceConfig.SpaceID)
|
instance, _ := c.gitspaceInstanceStore.FindLatestByGitspaceConfigID(ctx, gitspaceConfig.ID, gitspaceConfig.SpaceID)
|
||||||
gitspaceConfig.GitspaceInstance = instance
|
gitspaceConfig.GitspaceInstance = instance
|
||||||
gitspaceConfig.SpacePath = space.Path
|
gitspaceConfig.SpacePath = space.Path
|
||||||
if instance == nil {
|
if instance == nil || instance.State.IsFinalStatus() {
|
||||||
gitspaceConfig.IsDeleted = true
|
gitspaceConfig.IsDeleted = true
|
||||||
err = c.gitspaceSvc.UpdateConfig(ctx, gitspaceConfig)
|
err = c.gitspaceSvc.UpdateConfig(ctx, gitspaceConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to mark gitspace config as deleted: %w", err)
|
return fmt.Errorf("failed to mark gitspace config as deleted: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stopErr := c.stopRunningGitspace(ctx, *gitspaceConfig)
|
ctxWithoutCancel := context.WithoutCancel(ctx)
|
||||||
if stopErr != nil {
|
go c.stopRunningGitspace(ctxWithoutCancel, *gitspaceConfig)
|
||||||
return stopErr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) stopRunningGitspace(
|
func (c *Controller) stopRunningGitspace(ctx context.Context, config types.GitspaceConfig) {
|
||||||
ctx context.Context,
|
|
||||||
config types.GitspaceConfig,
|
|
||||||
) error {
|
|
||||||
config.GitspaceInstance.State = enum.GitspaceInstanceStateStopping
|
config.GitspaceInstance.State = enum.GitspaceInstanceStateStopping
|
||||||
err := c.gitspaceSvc.UpdateInstance(ctx, config.GitspaceInstance)
|
err := c.gitspaceSvc.UpdateInstance(ctx, config.GitspaceInstance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to update instance: %w", err)
|
log.Ctx(ctx).Err(err).Msgf("failed to update instance %s before triggering delete",
|
||||||
}
|
config.GitspaceInstance.Identifier)
|
||||||
err = c.orchestrator.TriggerDeleteGitspace(ctx, config)
|
return
|
||||||
if err != nil {
|
|
||||||
config.GitspaceInstance.State = enum.GitspaceInstanceStateError
|
|
||||||
updatErr := c.gitspaceSvc.UpdateInstance(ctx, config.GitspaceInstance)
|
|
||||||
if updatErr != nil {
|
|
||||||
return fmt.Errorf("failed to update instance: %w", updatErr)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
err = c.orchestrator.TriggerDeleteGitspace(ctx, config)
|
||||||
|
if err != nil {
|
||||||
|
log.Ctx(ctx).Err(err).Msgf("error during triggering delete for gitspace instance %s",
|
||||||
|
config.GitspaceInstance.Identifier)
|
||||||
|
|
||||||
|
config.GitspaceInstance.State = enum.GitspaceInstanceStateError
|
||||||
|
updateErr := c.gitspaceSvc.UpdateInstance(ctx, config.GitspaceInstance)
|
||||||
|
if updateErr != nil {
|
||||||
|
log.Ctx(ctx).Err(updateErr).Msgf("failed to update instance %s after error in triggering delete",
|
||||||
|
config.GitspaceInstance.Identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Ctx(ctx).Debug().Msgf("successfully triggered delete for gitspace instance %s",
|
||||||
|
config.GitspaceInstance.Identifier)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue