Automatic push from FunctionsAPI
This commit is contained in:
parent
36867179d7
commit
8c84b78d74
3488
Cargo.lock
generated
Normal file
3488
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "web"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
fathom-function = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "FTHM-11180/acr-corrosion-coupon" }
|
||||
pipeline-application = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git", branch = "FTHM-11180/acr-corrosion-coupon" }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
||||
uom = { version = "0.36" }
|
||||
uuid = { version = "1" }
|
||||
55
README.md
55
README.md
@ -1,2 +1,55 @@
|
||||
# f8e463a4b56d49b3acef584788ff5a27
|
||||
# Corrosion coupon report upload
|
||||
|
||||
A function that is used for creating corrosion coupon reports.
|
||||
|
||||
## 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
|
||||
- `coupon_retrieval_point_id`: an `array` of `strings` which should be valid UUIDs for coupon
|
||||
retrieval points on the pipeline
|
||||
- `installation_date`: a `string` formatted as an ISO date representing the date the corrosion
|
||||
coupon was installed in the pipeline.
|
||||
- `retrieval_date`: a `string` formatted as an ISO date representing the date the corrosion
|
||||
coupon was retrieved from the pipeline.
|
||||
- `metal_loss`: a `float` representing the measured metal loss of the token.
|
||||
- `inspector`: a `string` representing the identifier of the inspector
|
||||
- `remarks`: a `string` for any additional remarks about the inspection
|
||||
|
||||
## 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/coupon_retrieval_point_id \
|
||||
-d "Creates new corrosion coupon reports" \
|
||||
-i org_id=string \
|
||||
-i project_id=string \
|
||||
-i pipeline_id=array \
|
||||
-i coupon_retrieval_point_id=array \
|
||||
-i installation_date=string \
|
||||
-i retrieval_date=string \
|
||||
-i metal_loss=float \
|
||||
-i inspector=string \
|
||||
-i remarks=string
|
||||
```
|
||||
|
||||
## 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/coupon_retrieval_point_id/example_input.json)
|
||||
```
|
||||
|
||||
7
example_input.json
Normal file
7
example_input.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"org_id": "2cbfe270-d195-48ad-aed1-24145924635c",
|
||||
"pipeline_id": [
|
||||
"01966d47-1d4c-7751-a1f1-0617caa3a00d"
|
||||
],
|
||||
"project_id": "680b61b0aedd6f9e639d8699"
|
||||
}
|
||||
74
src/main.rs
Normal file
74
src/main.rs
Normal file
@ -0,0 +1,74 @@
|
||||
use fathom_function::{chrono::NaiveDate, forms::deserialize_date, tracing};
|
||||
use pipeline_application::{
|
||||
application::{Application, CorrosionCouponInitialReport},
|
||||
serialization::serialize_gram,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uom::si::f64::Mass;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[fathom_function::function]
|
||||
async fn upload_corrosion_coupon_report(input: Input) -> Result<Output, String> {
|
||||
let app = Application::new_from_compile_env(input.org_id, input.project_id).unwrap();
|
||||
|
||||
for (pipeline_id, coupon_retrieval_point_id) in input
|
||||
.pipeline_id
|
||||
.into_iter()
|
||||
.zip(input.coupon_retrieval_point_id)
|
||||
{
|
||||
app.upload_corrosion_coupon_report(pipeline_id, coupon_retrieval_point_id, &input.report)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!(%pipeline_id, ?err, "Error updating facility locations");
|
||||
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>,
|
||||
coupon_retrieval_point_id: Vec<Uuid>,
|
||||
#[serde(flatten)]
|
||||
report: Report,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Report {
|
||||
/// The date this corrosion coupon was installed in the pipeline.
|
||||
#[serde(deserialize_with = "deserialize_date")]
|
||||
installation_date: NaiveDate,
|
||||
/// The date this corrosion coupon was removed from the pipeline.
|
||||
#[serde(deserialize_with = "deserialize_date")]
|
||||
retrieval_date: NaiveDate,
|
||||
/// The metal loss of the coupon during the days exposed in the pipeline
|
||||
#[serde(with = "serialize_gram")]
|
||||
metal_loss: Mass,
|
||||
/// The inspector name or identifier
|
||||
inspector: String,
|
||||
/// And additional remarks about the inspection
|
||||
remarks: Option<String>,
|
||||
}
|
||||
|
||||
impl From<&Report> for CorrosionCouponInitialReport {
|
||||
fn from(value: &Report) -> Self {
|
||||
Self {
|
||||
installation_date: value.installation_date,
|
||||
retrieval_date: value.retrieval_date,
|
||||
metal_loss: value.metal_loss,
|
||||
inspector: value.inspector.to_owned(),
|
||||
remarks: value.remarks.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user