Skip to content

Commit

Permalink
fix: continuing to rip stuff out
Browse files Browse the repository at this point in the history
  • Loading branch information
nravic committed Mar 27, 2024
1 parent f646cdf commit c558fba
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 495,624 deletions.
63 changes: 59 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var createInstanceCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
r := BuildRunner()
err := r.createInstance(CreateInstanceRequest{
err := r.createInstance(cmd.Context(), CreateInstanceRequest{
TaskID: args[0],
})
if err != nil {
Expand All @@ -121,13 +121,26 @@ var setupInstanceCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
r := BuildRunner()
err := r.setupInstance(args[0])
err := r.setupInstance(cmd.Context(), args[0])
if err != nil {
r.logger.Fatal().Err(err).Msg("could not setup instance")
}
},
}

var listInstancesCmd = &cobra.Command{
Use: "list",
Short: "List all instances associated w/ owner",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
r := BuildRunner()
err := r.listInstances()

Check failure on line 137 in cmd/run.go

View workflow job for this annotation

GitHub Actions / build

not enough arguments in call to r.listInstances
if err != nil {
r.logger.Fatal().Err(err).Msg("could not list instances")
}
},
}

type setupTaskRequest struct {
TaskConfig string `json:"task_config"`
TaskLabel string `json:"label"`
Expand Down Expand Up @@ -231,7 +244,7 @@ type CreateInstanceResponse struct {
InstanceID string `json:"instance_id"`
}

func (r *Runner) createInstance(instanceReq CreateInstanceRequest) error {
func (r *Runner) createInstance(ctx context.Context, instanceReq CreateInstanceRequest) error {
r.logger.Info().Msgf("Creating instance for task: %s", instanceReq.TaskID)
jsonBody, err := json.Marshal(instanceReq)
if err != nil {
Expand Down Expand Up @@ -271,7 +284,7 @@ func (r *Runner) createInstance(instanceReq CreateInstanceRequest) error {
return nil
}

func (r *Runner) setupInstance(instanceID string) error {
func (r *Runner) setupInstance(ctx context.Context, instanceID string) error {
// Interrupt handler to gracefully close the WebSocket connection.
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
Expand Down Expand Up @@ -326,6 +339,48 @@ func (r *Runner) setupInstance(instanceID string) error {
}
}

type ListInstancesResponse struct {
InstanceID string `json:"instance_id"`
ProviderID string `json:"provider_id"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Price string `json:"price"`
Region string `json:"region"`
Provider string `json:"provider"`
}

func (r *Runner) listInstances(ctx context.Context) error {
url := r.cfg.MarketServiceUrl + "/instance"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+r.cfg.AuthToken)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("request failed with status code: %d", resp.StatusCode)
}

var str ListInstancesResponse
err = json.NewDecoder(resp.Body).Decode(&str)
if err != nil {
return err
}

return nil
}

func init() {
RootCmd.AddCommand(setupTaskCmd)
RootCmd.AddCommand(listTasksCmd)
Expand Down
26,175 changes: 0 additions & 26,175 deletions market/catalog/aws.csv

This file was deleted.

Loading

0 comments on commit c558fba

Please sign in to comment.