Cargo fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use chrono::{NaiveDate, Utc};
|
||||
use opentelemetry::trace::{Span, Status, TraceContextExt, Tracer};
|
||||
use opentelemetry::KeyValue;
|
||||
use opentelemetry::trace::{Span, Status, TraceContextExt, Tracer};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::time::sleep;
|
||||
@@ -34,34 +34,33 @@ pub async fn generate_daily_summaries(
|
||||
let start = start_date.unwrap_or_else(|| NaiveDate::from_ymd_opt(2024, 7, 1).unwrap());
|
||||
let end = end_date.unwrap_or_else(|| NaiveDate::from_ymd_opt(2024, 9, 30).unwrap());
|
||||
|
||||
parent_cx.span().set_attribute(KeyValue::new("start_date", start.to_string()));
|
||||
parent_cx.span().set_attribute(KeyValue::new("end_date", end.to_string()));
|
||||
parent_cx.span().set_attribute(KeyValue::new("date_range_days", (end - start).num_days() + 1));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("start_date", start.to_string()));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("end_date", end.to_string()));
|
||||
parent_cx.span().set_attribute(KeyValue::new(
|
||||
"date_range_days",
|
||||
(end - start).num_days() + 1,
|
||||
));
|
||||
|
||||
log::info!(
|
||||
"========================================");
|
||||
log::info!("========================================");
|
||||
log::info!("Starting daily summary generation for {}", contact);
|
||||
log::info!("Date range: {} to {} ({} days)",
|
||||
start, end, (end - start).num_days() + 1
|
||||
log::info!(
|
||||
"Date range: {} to {} ({} days)",
|
||||
start,
|
||||
end,
|
||||
(end - start).num_days() + 1
|
||||
);
|
||||
log::info!("========================================");
|
||||
|
||||
// Fetch all messages for the contact in the date range
|
||||
log::info!("Fetching messages for date range...");
|
||||
let _start_timestamp = start
|
||||
.and_hms_opt(0, 0, 0)
|
||||
.unwrap()
|
||||
.and_utc()
|
||||
.timestamp();
|
||||
let _end_timestamp = end
|
||||
.and_hms_opt(23, 59, 59)
|
||||
.unwrap()
|
||||
.and_utc()
|
||||
.timestamp();
|
||||
let _start_timestamp = start.and_hms_opt(0, 0, 0).unwrap().and_utc().timestamp();
|
||||
let _end_timestamp = end.and_hms_opt(23, 59, 59).unwrap().and_utc().timestamp();
|
||||
|
||||
let all_messages = sms_client
|
||||
.fetch_all_messages_for_contact(contact)
|
||||
.await?;
|
||||
let all_messages = sms_client.fetch_all_messages_for_contact(contact).await?;
|
||||
|
||||
// Filter to date range and group by date
|
||||
let mut messages_by_date: HashMap<NaiveDate, Vec<SmsMessage>> = HashMap::new();
|
||||
@@ -109,7 +108,10 @@ pub async fn generate_daily_summaries(
|
||||
let mut dao = summary_dao.lock().expect("Unable to lock DailySummaryDao");
|
||||
let otel_context = opentelemetry::Context::new();
|
||||
|
||||
if dao.summary_exists(&otel_context, &date_str, contact).unwrap_or(false) {
|
||||
if dao
|
||||
.summary_exists(&otel_context, &date_str, contact)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
skipped += 1;
|
||||
if idx % 10 == 0 {
|
||||
log::info!(
|
||||
@@ -171,17 +173,32 @@ pub async fn generate_daily_summaries(
|
||||
|
||||
log::info!("========================================");
|
||||
log::info!("Daily summary generation complete!");
|
||||
log::info!("Processed: {}, Skipped: {}, Failed: {}", processed, skipped, failed);
|
||||
log::info!(
|
||||
"Processed: {}, Skipped: {}, Failed: {}",
|
||||
processed,
|
||||
skipped,
|
||||
failed
|
||||
);
|
||||
log::info!("========================================");
|
||||
|
||||
// Record final metrics in span
|
||||
parent_cx.span().set_attribute(KeyValue::new("days_processed", processed as i64));
|
||||
parent_cx.span().set_attribute(KeyValue::new("days_skipped", skipped as i64));
|
||||
parent_cx.span().set_attribute(KeyValue::new("days_failed", failed as i64));
|
||||
parent_cx.span().set_attribute(KeyValue::new("total_days", total_days as i64));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("days_processed", processed as i64));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("days_skipped", skipped as i64));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("days_failed", failed as i64));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_attribute(KeyValue::new("total_days", total_days as i64));
|
||||
|
||||
if failed > 0 {
|
||||
parent_cx.span().set_status(Status::error(format!("{} days failed to process", failed)));
|
||||
parent_cx
|
||||
.span()
|
||||
.set_status(Status::error(format!("{} days failed to process", failed)));
|
||||
} else {
|
||||
parent_cx.span().set_status(Status::Ok);
|
||||
}
|
||||
@@ -252,14 +269,21 @@ Summary:"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
log::debug!("Generated summary for {}: {}", date, summary.chars().take(100).collect::<String>());
|
||||
log::debug!(
|
||||
"Generated summary for {}: {}",
|
||||
date,
|
||||
summary.chars().take(100).collect::<String>()
|
||||
);
|
||||
|
||||
span.set_attribute(KeyValue::new("summary_length", summary.len() as i64));
|
||||
|
||||
// Embed the summary
|
||||
let embedding = ollama.generate_embedding(&summary).await?;
|
||||
|
||||
span.set_attribute(KeyValue::new("embedding_dimensions", embedding.len() as i64));
|
||||
span.set_attribute(KeyValue::new(
|
||||
"embedding_dimensions",
|
||||
embedding.len() as i64,
|
||||
));
|
||||
|
||||
// Store in database
|
||||
let insert = InsertDailySummary {
|
||||
@@ -276,7 +300,8 @@ Summary:"#,
|
||||
let child_cx = opentelemetry::Context::current_with_span(span);
|
||||
|
||||
let mut dao = summary_dao.lock().expect("Unable to lock DailySummaryDao");
|
||||
let result = dao.store_summary(&child_cx, insert)
|
||||
let result = dao
|
||||
.store_summary(&child_cx, insert)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to store summary: {:?}", e));
|
||||
|
||||
match &result {
|
||||
|
||||
Reference in New Issue
Block a user