-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also can purge Issue #120
- Loading branch information
Showing
4 changed files
with
181 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package nomad | ||
|
||
import ( | ||
"fmt" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/hashicorp/nomad/api" | ||
) | ||
|
||
var ( | ||
JobAdminActions = map[AdminAction]string{ | ||
StopJobAction: "Stop", | ||
StopAndPurgeJobAction: "Stop and purge", | ||
} | ||
) | ||
|
||
type JobAdminActionCompleteMsg struct { | ||
Err error | ||
JobID string | ||
} | ||
|
||
func GetJobAdminText(adminAction AdminAction, jobID string) string { | ||
switch adminAction { | ||
case StopJobAction, StopAndPurgeJobAction: | ||
return fmt.Sprintf( | ||
"%s job %s", | ||
JobAdminActions[adminAction], jobID) | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
func GetCmdForJobAdminAction( | ||
client api.Client, | ||
adminAction AdminAction, | ||
jobID, jobNamespace string, | ||
) tea.Cmd { | ||
switch adminAction { | ||
case StopJobAction: | ||
return StopJob(client, jobID, jobNamespace, false) | ||
case StopAndPurgeJobAction: | ||
return StopJob(client, jobID, jobNamespace, true) | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
func StopJob(client api.Client, jobID, jobNamespace string, purge bool) tea.Cmd { | ||
return func() tea.Msg { | ||
opts := &api.WriteOptions{Namespace: jobNamespace} | ||
_, _, err := client.Jobs().Deregister(jobID, purge, opts) | ||
if err != nil { | ||
return JobAdminActionCompleteMsg{ | ||
Err: err, | ||
JobID: jobID, | ||
} | ||
} | ||
|
||
return JobAdminActionCompleteMsg{JobID: jobID} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters