Automatic push from FunctionsAPI
This commit is contained in:
parent
287ffdd1b7
commit
999170b277
3423
Cargo.lock
generated
Normal file
3423
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "web"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
fathom-function = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "main" }
|
||||
pipeline-application = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "main" }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||
uuid = { version = "1" }
|
||||
42
README.md
42
README.md
@ -1,2 +1,42 @@
|
||||
# 57f1e9b221194d1a9b18ef9bc5ef333f
|
||||
# Local Growth Rate
|
||||
|
||||
A function that calculates the local growth rate from an existing ILI comparison
|
||||
|
||||
## Input
|
||||
|
||||
### Arguments
|
||||
|
||||
- `org_id`: as string which should be a valid `uuid` for the organization
|
||||
- `project_id`: the id of the data project where the pipeline data is found
|
||||
- `pipeline_id`: an `array` of `strings` which should be valid UUIDs for pipelines
|
||||
- `ili_comparison_id`: an `array` of `strings` which should be valid UUIDs an ILI comparison sequence
|
||||
|
||||
## Creating the function on the platform
|
||||
|
||||
To create this function on the platform using the `cli` set up the port forwarding as shown in README.
|
||||
|
||||
Then run the following command to create the function.
|
||||
|
||||
```bash
|
||||
cargo run functions create \
|
||||
-f functions/acr_local_growth_rate \
|
||||
-d "Runs the local growth rate calculation based of a previous ILI comparison" \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i ili_comparison_id=array
|
||||
```
|
||||
|
||||
## Testing the function locally
|
||||
|
||||
You can run and test the function locally by running
|
||||
|
||||
```bash
|
||||
cargo run
|
||||
```
|
||||
|
||||
Then you can check it work with `curl` as follows
|
||||
|
||||
```bash
|
||||
curl localhost:8080 -d $(jq '. | tojson' functions/acr_local_growth_rate/example_input.json)
|
||||
```
|
||||
|
||||
10
example_input.json
Normal file
10
example_input.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||
"pipeline_id": [
|
||||
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||
],
|
||||
"ili_comparison_id": [
|
||||
"d95564b5-c077-453d-a7d2-a4116974222a"
|
||||
],
|
||||
"project_id": "680b61b0aedd6f9e639d8699"
|
||||
}
|
||||
37
src/main.rs
Normal file
37
src/main.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use fathom_function::tracing;
|
||||
use pipeline_application::application::Application;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn local_corrosion_growth_rate(input: Input) -> Result<Output, String> {
|
||||
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
||||
|
||||
for (pipeline_id, ili_comparison_id) in
|
||||
input.pipeline_id.into_iter().zip(input.ili_comparison_id)
|
||||
{
|
||||
app.local_corrosion_growth_rate(pipeline_id, ili_comparison_id)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!(%pipeline_id, ?err, "Error calculating local corrosion growth rate");
|
||||
format!("{err:?}")
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(Output {
|
||||
status: "Success".to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct Output {
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Input {
|
||||
org_id: Uuid,
|
||||
project_id: String,
|
||||
pipeline_id: Vec<Uuid>,
|
||||
ili_comparison_id: Vec<Uuid>,
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user