Skip to content

Commit 58531e7

Browse files
authored
Fix max machines API call (#136)
1 parent 9afea2b commit 58531e7

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

cmd/execute/execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func run(cfg *Config) error {
199199
return fmt.Errorf("failed to get workflow version: %w", err)
200200
}
201201

202-
workflowMaxMachines, err := client.GetWorkflowVersionMaxMachineCount(ctx, workflowVersion.ID, fleet.ID)
202+
workflowMaxMachines, err := client.GetWorkflowVersionMaxMachines(ctx, workflowVersion.ID, fleet.ID)
203203
if err != nil {
204204
return fmt.Errorf("failed to get workflow version max machine count: %w", err)
205205
}

cmd/help/help.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,7 @@ func run(cfg *Config) error {
242242
if err == nil {
243243
maxMachines, err := client.GetWorkflowVersionMaxMachines(ctx, workflowVersion.ID, fleet.ID)
244244
if err == nil {
245-
if maxMachines.Default != nil {
246-
versionMaxMachines = *maxMachines.Default
247-
}
248-
if maxMachines.SelfHosted != nil {
249-
versionMaxMachines = *maxMachines.SelfHosted
250-
}
245+
versionMaxMachines = maxMachines
251246
}
252247
}
253248

pkg/trickest/run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ type Machines struct {
5959
SelfHosted *int `json:"self_hosted,omitempty"`
6060
}
6161

62+
type Parallelism struct {
63+
Parallelism int `json:"parallelism"`
64+
}
65+
6266
type RunSubJobInsights struct {
6367
Total int `json:"total"`
6468
Pending int `json:"pending"`

pkg/trickest/workflow.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -301,33 +301,17 @@ func (c *Client) GetLatestWorkflowVersion(ctx context.Context, workflowID uuid.U
301301
}
302302

303303
// GetWorkflowVersionMaxMachines retrieves the maximum machines for a workflow version
304-
func (c *Client) GetWorkflowVersionMaxMachines(ctx context.Context, versionID uuid.UUID, fleetID uuid.UUID) (*Machines, error) {
305-
var machines Machines
304+
func (c *Client) GetWorkflowVersionMaxMachines(ctx context.Context, versionID uuid.UUID, fleetID uuid.UUID) (int, error) {
305+
var parallelism Parallelism
306306
path := fmt.Sprintf("/workflow-version/%s/max-machines/?fleet=%s", versionID, fleetID)
307307

308-
if err := c.Hive.doJSON(ctx, http.MethodGet, path, nil, &machines); err != nil {
309-
return nil, fmt.Errorf("failed to get workflow version max machines: %w", err)
310-
}
311-
312-
return &machines, nil
313-
}
314-
315-
// GetWorkflowVersionMaxMachineCount is a convenience function that retrieves the maximum machines for a workflow version as an int
316-
func (c *Client) GetWorkflowVersionMaxMachineCount(ctx context.Context, versionID uuid.UUID, fleetID uuid.UUID) (int, error) {
317-
machines, err := c.GetWorkflowVersionMaxMachines(ctx, versionID, fleetID)
318-
if err != nil {
308+
if err := c.Hive.doJSON(ctx, http.MethodGet, path, nil, &parallelism); err != nil {
319309
return 0, fmt.Errorf("failed to get workflow version max machines: %w", err)
320310
}
321-
322-
if machines.Default != nil {
323-
return *machines.Default, nil
324-
}
325-
326-
if machines.SelfHosted != nil {
327-
return *machines.SelfHosted, nil
311+
if parallelism.Parallelism <= 0 {
312+
return 0, fmt.Errorf("invalid max machines value: %d", parallelism.Parallelism)
328313
}
329-
330-
return 0, fmt.Errorf("no max machines found for workflow version")
314+
return parallelism.Parallelism, nil
331315
}
332316

333317
func (c *Client) CreateWorkflowVersion(ctx context.Context, version *WorkflowVersion) (*WorkflowVersion, error) {

0 commit comments

Comments
 (0)