Skip to content

Commit

Permalink
Sqs Event Handler Type
Browse files Browse the repository at this point in the history
  • Loading branch information
judegiordano committed Nov 22, 2023
1 parent a5203a8 commit 4ecfe9d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/bin/handlers/queues/create-output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Result;
use aws_lambda_events::event::sqs::SqsEvent;
use lambda_runtime::{run, service_fn, LambdaEvent};
use mongoose::{bson::doc, Model};
use parrot_api::{
aws::{s3::Client, sqs::FifoQueue},
aws::s3::Client,
eleven_labs::ElevenLabs,
env::Config,
logger,
Expand All @@ -10,19 +12,15 @@ use parrot_api::{
types::CreateOutputFifoMessage,
};

#[allow(unused_variables)]
#[tokio::main]
pub async fn main() -> Result<()> {
logger::init()?;
pub async fn handler(event: LambdaEvent<SqsEvent>) -> Result<()> {
let messages = event.payload.records;
let config = Config::new()?;
let voice_api = ElevenLabs::new()?;
let sqs = FifoQueue::new(config.create_output_queue_url).await;
let outputs_bucket = Client::new(&config.outputs_bucket_name).await;
let messages = sqs
.receive_fifo_message::<CreateOutputFifoMessage>()
.await?;
for message in messages {
let output = Output::read_by_id(&message.output_id).await?;
let body = message.body.unwrap();
let data = serde_json::from_str::<CreateOutputFifoMessage>(&body)?;
let output = Output::read_by_id(&data.output_id).await?;
let voice = Voice::read_by_id(&output.voice).await?;
if voice.eleven_labs_id.is_none() {
anyhow::bail!("no eleven labs id supplied");
Expand All @@ -47,3 +45,9 @@ pub async fn main() -> Result<()> {
}
Ok(())
}

#[tokio::main]
pub async fn main() -> Result<(), lambda_http::Error> {
logger::init()?;
run(service_fn(handler)).await
}

0 comments on commit 4ecfe9d

Please sign in to comment.