-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/fatih/color" | ||
|
||
api "github.com/porter-dev/porter/api/client" | ||
"github.com/porter-dev/porter/cli/cmd/config" | ||
) | ||
|
||
// RunAppJobInput is the input for the RunAppJob function | ||
type RunAppJobInput struct { | ||
// CLIConfig is the CLI configuration | ||
CLIConfig config.CLIConfig | ||
// Client is the Porter API client | ||
Client api.Client | ||
|
||
AppName string | ||
JobName string | ||
} | ||
|
||
// RunAppJob triggers a job run for an app and returns without waiting for the job to complete | ||
func RunAppJob(ctx context.Context, inp RunAppJobInput) error { | ||
targetResp, err := inp.Client.DefaultDeploymentTarget(ctx, inp.CLIConfig.Project, inp.CLIConfig.Cluster) | ||
if err != nil { | ||
return fmt.Errorf("error calling default deployment target endpoint: %w", err) | ||
} | ||
|
||
resp, err := inp.Client.RunAppJob(ctx, inp.CLIConfig.Project, inp.CLIConfig.Cluster, inp.AppName, inp.JobName, targetResp.DeploymentTargetID) | ||
if err != nil { | ||
return fmt.Errorf("unable to run job: %w", err) | ||
} | ||
|
||
color.New(color.FgGreen).Println("Triggered job with id:", resp.JobRunID) // nolint:errcheck,gosec | ||
|
||
return nil | ||
} |