Skip to content

Commit

Permalink
Switch instance to env build deregister
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Sep 18, 2023
1 parent 9585efa commit e3dba3e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/api/internal/nomad/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (n *NomadClient) StartBuildingEnv(
meta,
)
if err != nil {
apiErr := n.DeleteInstance(envID, false)
apiErr := n.DeleteEnvBuild(*job.ID, false)
if apiErr != nil {
fmt.Printf("error in cleanup after failing to create instance of environment '%s':%+v", envID, apiErr.Msg)
}
Expand Down Expand Up @@ -169,3 +169,16 @@ func (n *NomadClient) StartBuildingEnv(

return buildResult, nil
}

func (n *NomadClient) DeleteEnvBuild(jobID string, purge bool) *api.APIError {
_, _, err := n.client.Jobs().Deregister(jobID, purge, nil)
if err != nil {
return &api.APIError{
Msg: fmt.Sprintf("cannot delete job '%s%s' job: %+v", buildJobNameWithSlash, jobID, err),
ClientMsg: "Cannot delete the environment instance right now",
Code: http.StatusInternalServerError,
}
}

return nil
}

0 comments on commit e3dba3e

Please sign in to comment.