Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active October 24, 2020 16:47
Show Gist options
  • Select an option

  • Save jayhuang75/a87949003516addb6c580818d705a84e to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/a87949003516addb6c580818d705a84e to your computer and use it in GitHub Desktop.
SMS alert covid main
// application start time
let start = Instant::now();
let now: Date<Local> = Local::now().date();
info!("[job] start at {:?}", now);
info!("[job] download url : {:?}", &*DOWNLOAD_FILE_URL);
// download the file
let download_file_name = format!("{}-{}", now, *DOWNLOAD_FILE_NAME);
let file_path: String = download::fetch(
&*DOWNLOAD_FILE_URL,
&*DOWNLOAD_DIR_NAME,
&download_file_name,
)
.await
.unwrap();
// process the data
let today_covid_report: Vec<alert::CovidStats> = process::run(&file_path).await.unwrap();
info!("[job] result: {:?}", today_covid_report);
if today_covid_report.len() != 0 {
let new_report = alert::CovidReport::new(today_covid_report, Box::new(alert::sms::Sms {}));
new_report.producer().await;
}
// remove tmp folder
remove_dir_all(&*DOWNLOAD_DIR_NAME).await.unwrap();
info!("[job] remove tmp");
// mesurement the elapsed time
let duration = start.elapsed();
info!("[job] end time elapsed in main(): {:?}", duration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment