diff --git a/internal/manager/manager.go b/internal/manager/manager.go index 73aad70..1d34814 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -151,6 +151,7 @@ func (m Manager) onDeployment(ctx context.Context, deploymentResult deployment.D m.isRunning = false m.prometheus.SetDeploymentInfo(m.deployment.Generation.SelectedCommitId, deployment.StatusToString(m.deployment.Status)) m.storage.DeploymentInsertAndCommit(m.deployment) + m.space.AgentUpdate(m.deployment) return m } diff --git a/internal/space/client.gen.go b/internal/space/client.gen.go index 65e32f0..9a3d0e9 100644 --- a/internal/space/client.gen.go +++ b/internal/space/client.gen.go @@ -57,7 +57,7 @@ type Deployment struct { Agent *Agent `json:"agent,omitempty"` AgentID openapi_types.UUID `json:"agentID"` BranchName string `json:"branchName"` - CommitDate string `json:"commitDate"` + CommitDate time.Time `json:"commitDate"` CommitID string `json:"commitID"` CommitMessage string `json:"commitMessage"` CreatedAt time.Time `json:"createdAt"` @@ -98,7 +98,7 @@ type NewDeployment struct { Agent *Agent `json:"agent,omitempty"` AgentID openapi_types.UUID `json:"agentID"` BranchName string `json:"branchName"` - CommitDate string `json:"commitDate"` + CommitDate time.Time `json:"commitDate"` CommitID string `json:"commitID"` CommitMessage string `json:"commitMessage"` EndedAt time.Time `json:"endedAt"` diff --git a/internal/space/space.go b/internal/space/space.go index 9a6c238..b4b7d61 100644 --- a/internal/space/space.go +++ b/internal/space/space.go @@ -24,7 +24,7 @@ func New(agentName, agentMachineID string) Space { apiKeyFilepath := os.Getenv("COMIN_SPACE_API_KEY_FILEPATH") apiKey, err := os.ReadFile(apiKeyFilepath) if err != nil { - logrus.Errorf("Could not read the password in the file %s: %s", apiKeyFilepath, err) + logrus.Errorf("space: could not read the password in the file %s: %s", apiKeyFilepath, err) } url := os.Getenv("COMIN_SPACE_URL") return Space{ @@ -42,9 +42,9 @@ func (s *Space) agentRegister(name, machineID string) error { req.Header.Set("Authorization", "token "+s.apiKey) return nil } - c, err := NewClientWithResponses(s.url, WithHTTPClient(&hc), WithRequestEditorFn(reqEditor)) + c, err := NewClientWithResponses(s.url+"/api", WithHTTPClient(&hc), WithRequestEditorFn(reqEditor)) if err != nil { - return err + return fmt.Errorf("space: failed to NewClientWithResponses: %s", err) } s.client = c } @@ -57,10 +57,10 @@ func (s *Space) agentRegister(name, machineID string) error { resp, err := s.client.GetAgentsWithResponse(ctx, &GetAgentsParams{MachineID: &s.agentMachineID}) if err != nil { - return err + return fmt.Errorf("space: failed to GetAgentsWithResponse: %s", err) } if resp.StatusCode() != http.StatusOK { - return fmt.Errorf("Expected HTTP 200 but received %d", resp.StatusCode()) + return fmt.Errorf("space: expected HTTP 200 but received %d", resp.StatusCode()) } agents := *resp.JSON200 if len(agents) == 1 { @@ -72,10 +72,10 @@ func (s *Space) agentRegister(name, machineID string) error { } resp, err := s.client.PostAgentsWithResponse(ctx, newAgent) if err != nil { - return err + return fmt.Errorf("space: failed to PostAgentsWithResponse: %s", err) } if resp.StatusCode() != http.StatusCreated { - return fmt.Errorf("Expected HTTP 201 but received %d", resp.StatusCode()) + return fmt.Errorf("space: expected HTTP 201 but received %d", resp.StatusCode()) } s.agentID = &resp.JSON201.Id } @@ -131,12 +131,12 @@ func (s *Space) AgentUpdate(d deployment.Deployment) { return } if resp.StatusCode() != http.StatusCreated { - logrus.Errorf("Expected HTTP 201 while updating the agent but received %d", resp.StatusCode()) + logrus.Errorf("space: expected HTTP 201 while updating the agent but received %d", resp.StatusCode()) return } if err := s.deploymentRegister(ctx, d); err != nil { - logrus.Errorf("Fail to register the deployment %s: %s", d.UUID, err) + logrus.Errorf("space: failed to register the deployment %s: %s", d.UUID, err) } else { // TODO: convert deployment.UUID to uuid type uuidStr, _ := uuid.Parse(d.UUID) @@ -150,7 +150,7 @@ func (s *Space) AgentUpdate(d deployment.Deployment) { return } if respPatch.StatusCode() != http.StatusOK { - logrus.Errorf("Expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode()) + logrus.Errorf("space: expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode()) return } }