-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tidy crates, add plain lambda for calling receive manually
- Loading branch information
Showing
14 changed files
with
145 additions
and
156 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
34 changes: 21 additions & 13 deletions
34
lib/workload/stateless/filemanager/filemanager-http-lambda/src/main.rs
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 |
---|---|---|
@@ -1,22 +1,30 @@ | ||
use axum::{ | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
use lambda_http::{run, Error}; | ||
use filemanager::database::s3::ingester::Ingester; | ||
use filemanager::events::s3::s3::S3; | ||
use filemanager::events::s3::sqs::SQS; | ||
use lambda_http::Error; | ||
use lambda_runtime::{run, service_fn, LambdaEvent}; | ||
|
||
/// Handle SQS events. | ||
async fn event_handler(_: LambdaEvent<()>) -> Result<(), Error> { | ||
let sqs = SQS::with_default_client().await?; | ||
let events = sqs.receive().await?; | ||
|
||
let s3 = S3::with_defaults().await?; | ||
let events = s3.update_events(events).await?; | ||
|
||
let mut ingester = Ingester::new_with_defaults().await?; | ||
|
||
ingester.ingest_events(events.into()).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
// required to enable CloudWatch error logging by the runtime | ||
tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::INFO) | ||
// disable printing the name of the module in every log line. | ||
.with_target(false) | ||
// disabling time is handy because CloudWatch will add the ingestion time. | ||
.without_time() | ||
.init(); | ||
|
||
// Todo add axum routes here. | ||
todo!(); | ||
|
||
//run(app).await | ||
run(service_fn(event_handler)).await | ||
} |
41 changes: 19 additions & 22 deletions
41
lib/workload/stateless/filemanager/filemanager-ingest-lambda/src/main.rs
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 |
---|---|---|
@@ -1,44 +1,41 @@ | ||
use aws_lambda_events::event::sqs::SqsEventObj; | ||
use aws_lambda_events::sqs::SqsEvent; | ||
use lambda_runtime::{run, service_fn, Error, LambdaEvent}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use filemanager::database::s3::ingester::Ingester; | ||
use filemanager::events::s3::{Events, FlatS3EventMessage, FlatS3EventMessages}; | ||
use filemanager::events::s3::s3::S3; | ||
|
||
/// This is the main body for the function. | ||
/// You can use the data sent into SQS here. | ||
async fn function_handler(event: LambdaEvent<SqsEvent>) -> Result<(), Error> { | ||
let events = event.payload.records.into_iter().filter_map(|event| { | ||
event.body.map(|body| { | ||
let body: FlatS3EventMessages = serde_json::from_str(&body).unwrap(); | ||
body | ||
use filemanager::events::s3::FlatS3EventMessages; | ||
|
||
/// Handle SQS events. | ||
async fn event_handler(event: LambdaEvent<SqsEvent>) -> Result<(), Error> { | ||
let events: FlatS3EventMessages = event | ||
.payload | ||
.records | ||
.into_iter() | ||
.filter_map(|event| { | ||
event.body.map(|body| { | ||
let body: FlatS3EventMessages = serde_json::from_str(&body).unwrap(); | ||
body | ||
}) | ||
}) | ||
}).collect::<Vec<FlatS3EventMessages>>(); | ||
.collect::<Vec<FlatS3EventMessages>>() | ||
.into(); | ||
|
||
let e = events.into_iter().next().unwrap().body; | ||
let s3 = S3::with_defaults().await?; | ||
let e = s3.update_events(e).await?; | ||
|
||
let e = Events::from(e); | ||
let events = s3.update_events(events).await?; | ||
|
||
let mut ingester = Ingester::new_with_defaults().await?; | ||
|
||
ingester.ingest_events(e).await?; | ||
ingester.ingest_events(events.into()).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
// required to enable CloudWatch error logging by the runtime | ||
tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::INFO) | ||
// disable printing the name of the module in every log line. | ||
.with_target(false) | ||
// disabling time is handy because CloudWatch will add the ingestion time. | ||
.without_time() | ||
.init(); | ||
|
||
run(service_fn(function_handler)).await | ||
run(service_fn(event_handler)).await | ||
} |
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
4 changes: 2 additions & 2 deletions
4
lib/workload/stateless/filemanager/filemanager/src/database/s3/mod.rs
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
6 changes: 3 additions & 3 deletions
6
lib/workload/stateless/filemanager/filemanager/src/events/mod.rs
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
Oops, something went wrong.