-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Run exec agent #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
8223bd0
01bc449
e1a6568
2d98dd4
2d395fb
f01a216
eae19f1
df80fe2
a29b566
ab92d45
6d1fda9
6e6e77c
840e166
3660019
f51d8d4
5160555
c6fdca4
09ccdc6
33ea1ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,10 @@ type ExecConfig struct { | |
| } | ||
|
|
||
| func (r *ExecRunner) Status(job api.Job) (api.JobStatus, string) { | ||
|
||
| if job.ExternalId == nil { | ||
| return api.JobStatusExternalRunNotFound, fmt.Sprintf("external ID is nil: %v", job.ExternalId) | ||
| } | ||
|
|
||
| externalId, err := strconv.Atoi(*job.ExternalId) | ||
| if err != nil { | ||
| return api.JobStatusExternalRunNotFound, fmt.Sprintf("invalid process id: %v", err) | ||
|
|
@@ -45,7 +49,7 @@ func (r *ExecRunner) Status(job api.Job) (api.JobStatus, string) { | |
| return api.JobStatusInProgress, fmt.Sprintf("process running with pid %d", externalId) | ||
| } | ||
|
|
||
| func (r *ExecRunner) Start(job api.Job) (string, error) { | ||
| func (r *ExecRunner) Start(job api.Job, jobDetails map[string]interface{}) (string, error) { | ||
| // Create temp script file | ||
| ext := ".sh" | ||
| if runtime.GOOS == "windows" { | ||
|
|
@@ -73,7 +77,7 @@ func (r *ExecRunner) Start(job api.Job) (string, error) { | |
| } | ||
|
|
||
| buf := new(bytes.Buffer) | ||
| if err := templatedScript.Execute(buf, job); err != nil { | ||
| if err := templatedScript.Execute(buf, jobDetails); err != nil { | ||
|
||
| return "", fmt.Errorf("failed to execute script template: %w", err) | ||
| } | ||
| script := buf.String() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package jobagent | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func fetchJobDetails(ctx context.Context, jobID string) (map[string]interface{}, error) { | ||
| client, err := api.NewAPIKeyClientWithResponses(viper.GetString("url"), viper.GetString("api-key")) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create API client for job details: %w", err) | ||
| } | ||
|
|
||
| resp, err := client.GetJobWithResponse(ctx, jobID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get job details: %w", err) | ||
| } | ||
| if resp.JSON200 == nil { | ||
| return nil, fmt.Errorf("received empty response from job details API") | ||
| } | ||
|
|
||
| var details map[string]interface{} | ||
| detailsBytes, err := json.Marshal(resp.JSON200) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to marshal job response: %w", err) | ||
| } | ||
| if err := json.Unmarshal(detailsBytes, &details); err != nil { | ||
| return nil, fmt.Errorf("failed to unmarshal job details: %w", err) | ||
| } | ||
| return details, nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could move input validation above the client creation?