Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.3 KB
Raw Blame
mod config;
mod context;
mod handler;

use anyhow::Context;
use aws_lambda_events::event::eventbridge::EventBridgeEvent;
use config::Config;
use handler::handler;
use lambda_runtime::{Error, LambdaEvent, run, service_fn};
use macro_entrypoint::MacroEntrypoint;
use sqlx::postgres::PgPoolOptions;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Error> {
    MacroEntrypoint::default().init();

    let config = Config::from_env().context("all necessary env vars should be available")?;

    // should only need a single connection to fetch the list of emails
    let db = PgPoolOptions::new()
        .min_connections(1)
        .max_connections(1)
        .connect(&config.database_url)
        .await
        .context("could not connect to db")?;

    let sfs_delete_queue = macro_queues::SfsDeleteQueue::new();
    let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(
        &macro_aws_config::get_macro_aws_config().await,
    ))
    .sfs_delete_queue(&sfs_delete_queue);

    let ctx = context::Context {
        db,
        sqs_client: Arc::new(sqs_client),
    };

    let func = service_fn(move |event: LambdaEvent<EventBridgeEvent>| {
        let ctx = ctx.clone();

        async move { handler(ctx, event).await }
    });

    run(func).await
}