Skip to content
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

Support array result include sequence action #39

Conversation

ningyougang
Copy link
Contributor

@ningyougang ningyougang commented Jul 26, 2022

Depend on below prs:

@ningyougang
Copy link
Contributor Author

The rust supports sequence action by default, test steps as below

  • Write split.rs and sort.rs
extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Input {
    #[serde(default = "stranger")]
    name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Output {
    greeting: String,
}

fn stranger() -> String {
    "stranger".to_string()
}

pub fn main(args: Value) -> Result<Value, Error> {
    // has no split, just return array, need to receive this value in next action(sort)
    let output = ["a", "b"];
    serde_json::to_value(output)
}

extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Input {
    #[serde(default = "stranger")]
    name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
struct Output {
    greeting: String,
}

fn stranger() -> String {
    "stranger".to_string()
}

pub fn main(args: Value) -> Result<Value, Error> {
    println!("param args is {}", args);

    let inputParam = args.as_array();
    println!("input param as array is {:?}", inputParam);

    let defaultOutput = ["finally-a", "finally-b"];
    match inputParam {
       None => serde_json::to_value(defaultOutput),
       Some(x) => serde_json::to_value(x),
    }
}
  • Create the action and invoke it
wsk -i action create /whisk.system/utils/split-rust --kind rust:1.34 ~/split.rs
wsk -i action create /whisk.system/utils/sort-rust --kind rust:1.34 ~/sort.rs
wsk -i action create mySequence-rust --sequence /whisk.system/utils/split-rust,/whisk.system/utils/sort-rust
wsk -i action invoke --result mySequence-rust -r -v

refer to: https://docs.serde.rs/serde_json/value/enum.Value.html

@ningyougang ningyougang force-pushed the support-array-result-include-sequence-action branch from dc405c3 to 20dc889 Compare August 8, 2022 07:32

FROM rust:1.34

# select the builder to use
ARG GO_PROXY_BUILD_FROM=release
ARG GO_PROXY_BUILD_FROM=source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change it to release due to apache/openwhisk-runtime-java#140 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already changed to release

Copy link
Member

@dgrove-oss dgrove-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dgrove-oss dgrove-oss merged commit ebddcbd into apache:master Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants