diff --git a/charts/vela-workflow/templates/definitions/request.yaml b/charts/vela-workflow/templates/definitions/request.yaml index 969e08c..7877949 100644 --- a/charts/vela-workflow/templates/definitions/request.yaml +++ b/charts/vela-workflow/templates/definitions/request.yaml @@ -14,34 +14,45 @@ spec: cue: template: | import ( - "vela/op" - "encoding/json" + "vela/http" + "vela/op" + "encoding/json" ) - http: op.#HTTPDo & { - method: parameter.method - url: parameter.url - request: { - if parameter.body != _|_ { - body: json.Marshal(parameter.body) - } - if parameter.header != _|_ { - header: parameter.header - } - } - } + req: http.#HTTPDo & { + $params: { + method: parameter.method + url: parameter.url + request: { + if parameter.body != _|_ { + body: json.Marshal(parameter.body) + } + if parameter.header != _|_ { + header: parameter.header + } + } + } + } @step(1) + + wait: op.#ConditionalWait & { + continue: req.$returns != _|_ + message?: "Waiting for response from \(parameter.url)" + } @step(2) + fail: op.#Steps & { - if http.response.statusCode > 400 { - requestFail: op.#Fail & { - message: "request of \(parameter.url) is fail: \(http.response.statusCode)" - } - } - } - response: json.Unmarshal(http.response.body) + if req.$returns.statusCode > 400 { + requestFail: op.#Fail & { + message: "request of \(parameter.url) is fail: \(req.$returns.statusCode)" + } + } + } @step(3) + + response: json.Unmarshal(req.$returns.body) + parameter: { - url: string - method: *"GET" | "POST" | "PUT" | "DELETE" - body?: {...} - header?: [string]: string + url: string + method: *"GET" | "POST" | "PUT" | "DELETE" + body?: {...} + header?: [string]: string } diff --git a/pkg/providers/http/http.cue b/pkg/providers/http/http.cue index 403dc44..e757e6f 100644 --- a/pkg/providers/http/http.cue +++ b/pkg/providers/http/http.cue @@ -34,18 +34,15 @@ } $returns?: { - // +usage=The response of the request will be filled in this field after the action is executed - response: { - // +usage=The body of the response - body: string - // +usage=The header of the response - header?: [string]: [...string] - // +usage=The trailer of the response - trailer?: [string]: [...string] - // +usage=The status code of the response - statusCode: int - ... - } + // +usage=The body of the response + body: string + // +usage=The header of the response + header?: [string]: [...string] + // +usage=The trailer of the response + trailer?: [string]: [...string] + // +usage=The status code of the response + statusCode: int + ... } ... }