Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Mar 12, 2024
1 parent f0faad3 commit cfe3208
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ On MacOS you can install trunk with `brew install trunk-io`. If you're using nix

To lint all files that you've modified since the last commit, run `trunk check`. To fix any linter issues trunk can autoformat, run `trunk fmt`. To lint or format all files in the repo, specify -a like `trunk check -a`.

To rescan the repo for any new linters that should be configured, like when adding a new language, run `trunk upgrade`. This will also update linters to their latest version.

### Overview

When introducing changes to the project, note the following requirements:

- All changes to the main branch should be introduced via pull requests.
- All branches created for pull requests should follow the `dev/*` naming convention, e.g. `dev/coverage-reports`.
- Every pull request **must** be reviewed by at least one other peer prior to being merged into the main branch.
- Code **must** be supported on Linux, macOS, and Windows.
- Code **must** be sufficiently commented:
- Every type, function, const, and other variables should be accompanied by [doc comments](https://tip.golang.org/doc/comment).
- Inline comments should be provided for every block of code. These should explain what the block of code is aiming to achieve in plain english.
- Inline comments should be provided for every block of code. These should explain what the block of code is aiming to achieve in plain English.
- Inline comments should specify any non-trivial caveats with a given piece of code, considerations to make when maintaining it, etc.
- Any considerations regarding potential weaknesses or future improvements to be made within your code should be accompanied by an inline comment prefixed with `// TODO: `
- Comments should provide some value to a new contributor and improve code readability.
Expand Down
4 changes: 2 additions & 2 deletions cmd/cloudexec/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func ConfirmDeleteDroplets(config config.Config, dropletName string, instanceToJobs map[int64][]int64) ([]int64, error) {
confirmedToDelete := make([]int64)
var confirmedToDelete []int64
instances, err := do.GetDropletsByName(config, dropletName)
if err != nil {
return confirmedToDelete, fmt.Errorf("Failed to get droplets by name: %w", err)
Expand Down Expand Up @@ -44,7 +44,7 @@ func ConfirmDeleteDroplets(config config.Config, dropletName string, instanceToJ
if err != nil {
return confirmedToDelete, fmt.Errorf("Failed to destroy droplet: %w", err)
}
confirmedToDelete.push(instance.ID)
confirmedToDelete = append(confirmedToDelete, instance.ID)
}
}
} else {
Expand Down
18 changes: 10 additions & 8 deletions cmd/cloudexec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,27 @@ func main() {
return err
}

confirmedToDelete, err = ConfirmDeleteDroplets(config, dropletName, instanceToJobs)
// deletes droplets per user feedback & returns a list of job IDs for state updates
confirmedToDelete, err := ConfirmDeleteDroplets(config, dropletName, instanceToJobs)
if err != nil {
return err
}
if (confirmedToDelete.length == 0) {
if (len(confirmedToDelete) == 0) {
return nil
}
err = ssh.DeleteSSHConfig(user, "cloudexec")

existingState, err := state.GetState(config, bucketName)
if err != nil {
return err
}

existingState, err := state.GetState(config, bucketName)
// mark any running jobs as cancelled
err = existingState.CancelRunningJobs(config, bucketName, confirmedToDelete)
if err != nil {
return err
}

// mark any running jobs as cancelled
err = existingState.CancelRunningJobs(config, bucketName)
err = ssh.DeleteSSHConfig(user, "cloudexec")
if err != nil {
return err
}
Expand Down Expand Up @@ -262,11 +264,11 @@ func main() {
if err != nil {
return err
}
confirmedToDelete, err = ConfirmDeleteDroplets(config, dropletName, instanceToJobs)
confirmedToDelete, err := ConfirmDeleteDroplets(config, dropletName, instanceToJobs)
if err != nil {
return err
}
if (confirmedToDelete.length > 0) {
if (len(confirmedToDelete) > 0) {
err = ssh.DeleteSSHConfig(user, "cloudexec")
if err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ func (s *State) DeleteJob(jobID int64) {
}
}

func (s *State) CancelRunningJobs(config config.Config, bucketName string) error {
func (s *State) CancelRunningJobs(config config.Config, bucketName string, toCancel []int64) error {
// Mark any running jobs as cancelled
for i, job := range s.Jobs {
if job.Status == Running || job.Status == Provisioning {
s.Jobs[i].Status = Cancelled
for _, id := range toCancel {
if id == job.ID {
fmt.Printf("Setting status of job %d to 'Cancelled'\n", job.ID)
s.Jobs[i].Status = Cancelled
break
}
}
}
}

Expand Down

0 comments on commit cfe3208

Please sign in to comment.