-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
0 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
35 changes: 35 additions & 0 deletions
35
cmd/scw/testdata/test-all-usage-jobs-run-wait-usage.cassette.yaml
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,35 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' | ||
form: {} | ||
headers: | ||
User-Agent: | ||
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) cli-e2e-test | ||
url: https://api.scaleway.com/iam/v1alpha1/api-keys/SCWXXXXXXXXXXXXXXXXX | ||
method: GET | ||
response: | ||
body: '{"message":"authentication is denied","method":"api_key","reason":"not_found","type":"denied_authentication"}' | ||
headers: | ||
Content-Length: | ||
- "109" | ||
Content-Security-Policy: | ||
- default-src 'none'; frame-ancestors 'none' | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Mon, 11 Dec 2023 08:40:33 GMT | ||
Server: | ||
- Scaleway API-Gateway | ||
Strict-Transport-Security: | ||
- max-age=63072000 | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
X-Request-Id: | ||
- 535893cd-5245-4c83-876d-ee1f4f9ff93b | ||
status: 401 Unauthorized | ||
code: 401 | ||
duration: "" |
19 changes: 19 additions & 0 deletions
19
cmd/scw/testdata/test-all-usage-jobs-run-wait-usage.golden
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,19 @@ | ||
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 | ||
🟥🟥🟥 STDERR️️ 🟥🟥🟥️ | ||
Wait for a job run to reach a stable state. This is similar to using --wait flag. | ||
|
||
USAGE: | ||
scw jobs run wait <job-run-id ...> [arg=value ...] | ||
|
||
ARGS: | ||
job-run-id | ||
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) | ||
|
||
FLAGS: | ||
-h, --help help for wait | ||
|
||
GLOBAL FLAGS: | ||
-c, --config string The path to the config file | ||
-D, --debug Enable debug mode | ||
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human") | ||
-p, --profile string The config profile to use |
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
36 changes: 36 additions & 0 deletions
36
internal/namespaces/jobs/v1alpha1/custom_job_definition.go
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,36 @@ | ||
package jobs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/scaleway/scaleway-cli/v2/internal/core" | ||
jobs "github.com/scaleway/scaleway-sdk-go/api/jobs/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func definitionStartBuilder(c *core.Command) *core.Command { | ||
c.WaitUsage = "Wait until the job reach a stable state, use job definition timeout" | ||
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) { | ||
api := jobs.NewAPI(core.ExtractClient(ctx)) | ||
args := argsI.(*jobs.StartJobDefinitionRequest) | ||
resp := respI.(*jobs.JobRun) | ||
|
||
jobDefinition, err := api.GetJobDefinition(&jobs.GetJobDefinitionRequest{ | ||
Region: args.Region, | ||
JobDefinitionID: args.JobDefinitionID, | ||
}, scw.WithContext(ctx)) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch job definition for timeout: %w", err) | ||
} | ||
|
||
return api.WaitForJobRun(&jobs.WaitForJobRunRequest{ | ||
Region: args.Region, | ||
JobRunID: resp.ID, | ||
Timeout: jobDefinition.JobTimeout.ToTimeDuration(), | ||
RetryInterval: core.DefaultRetryInterval, | ||
}) | ||
} | ||
|
||
return c | ||
} |
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,38 @@ | ||
package jobs | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
|
||
"github.com/scaleway/scaleway-cli/v2/internal/core" | ||
jobs "github.com/scaleway/scaleway-sdk-go/api/jobs/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func jobsRunWait() *core.Command { | ||
return &core.Command{ | ||
Short: `Wait for a job run to reach a stable state`, | ||
Long: `Wait for a job run to reach a stable state. This is similar to using --wait flag.`, | ||
Namespace: "jobs", | ||
Resource: "run", | ||
Verb: "wait", | ||
// Deprecated: false, | ||
ArgsType: reflect.TypeOf(jobs.WaitForJobRunRequest{}), | ||
ArgSpecs: core.ArgSpecs{ | ||
{ | ||
Name: "job-run-id", | ||
Required: true, | ||
Deprecated: false, | ||
Positional: true, | ||
}, | ||
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw), | ||
}, | ||
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { | ||
request := args.(*jobs.WaitForJobRunRequest) | ||
|
||
client := core.ExtractClient(ctx) | ||
api := jobs.NewAPI(client) | ||
return api.WaitForJobRun(request) | ||
}, | ||
} | ||
} |