Skip to content

Commit

Permalink
Merge branch 'main' into output-checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Jan 12, 2024
2 parents 0dd50a0 + 530f2fa commit 1d5099b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/cloudexec/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Commands struct {
type LaunchConfig struct {
Commands Commands `toml:"commands"`
Input struct {
JobName string
Directory string
Timeout string
} `toml:"input"`
Expand Down Expand Up @@ -109,6 +110,7 @@ func Launch(user *user.User, config config.Config, dropletSize string, dropletRe
startedAt := time.Now().Unix()

newJob := state.JobInfo{
Name: lc.Input.JobName,
ID: thisJobId,
Status: state.Provisioning,
StartedAt: startedAt,
Expand Down
3 changes: 2 additions & 1 deletion cmd/cloudexec/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func PrintStatus(config config.Config, bucketName string, showAll bool) error {

// Print the status of each job using tablewriter
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Job ID", "Status", "Droplet IP", "Memory", "CPUs", "Disk", "Started At", "Updated At", "Time Elapsed", "Hourly Cost", "Total Cost"})
table.SetHeader([]string{"Job ID", "Job Name", "Status", "Droplet IP", "Memory", "CPUs", "Disk", "Started At", "Updated At", "Time Elapsed", "Hourly Cost", "Total Cost"})

formatDate := func(timestamp int64) string {
if timestamp == 0 {
Expand Down Expand Up @@ -78,6 +78,7 @@ func PrintStatus(config config.Config, bucketName string, showAll bool) error {

table.Append([]string{
strconv.Itoa(int(job.ID)),
job.Name,
string(job.Status),
job.Droplet.IP,
formatInt(job.Droplet.Size.Memory) + " MB",
Expand Down
2 changes: 2 additions & 0 deletions cmd/cloudexec/user_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ func getLaunchConfig(duration string) LaunchConfig {
Run: "echo 'lets run'",
},
Input: struct {
JobName string
Directory string
Timeout string
}{
JobName: "test job name",
Directory: "./input",
Timeout: duration,
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
)

type JobInfo struct {
Name string `json:"name"`
ID int64 `json:"id"`
StartedAt int64 `json:"started_at"` // Unix timestamp
CompletedAt int64 `json:"completed_at"`
Expand Down Expand Up @@ -53,6 +54,13 @@ func GetState(config config.Config, bucketName string) (*State, error) {
return nil, fmt.Errorf("Failed to unmarshal state JSON: %w", err)
}

// Replace empty names with a placeholder
for i, job := range state.Jobs {
if job.Name == "" {
state.Jobs[i].Name = "no name"
}
}

return &state, nil
}

Expand Down

0 comments on commit 1d5099b

Please sign in to comment.