Incorporate beachhead files from the previous mono-repo
This commit is contained in:
+3
-2
@@ -12,7 +12,7 @@ use axum::routing::{get, post};
|
||||
use axum::{Extension, Json, Router};
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use base64::Engine;
|
||||
use beachhead::{shutdown_signal, Result};
|
||||
use utils::{shutdown_signal, Result};
|
||||
use chrono::{NaiveDate, NaiveTime};
|
||||
use clap::Parser;
|
||||
use migration::{Migrator, MigratorTrait};
|
||||
@@ -30,6 +30,7 @@ mod db;
|
||||
mod entity;
|
||||
mod poll;
|
||||
mod types;
|
||||
mod utils;
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
struct Config {
|
||||
@@ -202,7 +203,7 @@ fn from_csv_row(row: csv::StringRecord) -> ActiveModel {
|
||||
async fn import_csv(
|
||||
Extension(db): Extension<DatabaseConnection>,
|
||||
mut multipart: Multipart,
|
||||
) -> beachhead::Result<impl IntoResponse> {
|
||||
) -> Result<impl IntoResponse> {
|
||||
return Ok((StatusCode::NOT_IMPLEMENTED, "Not implemented"));
|
||||
|
||||
// while let Some(field) = multipart.next_field().await? {
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ use crate::entity::{client, project, time_entry};
|
||||
use crate::types::{Project, ProjectClient, TogglQuery};
|
||||
use sea_orm::{DatabaseConnection, EntityTrait, QuerySelect};
|
||||
use tracing::instrument;
|
||||
use crate::day_exclusivity_condition;
|
||||
use crate::{day_exclusivity_condition, utils};
|
||||
|
||||
#[tracing::instrument(skip(client, db))]
|
||||
pub async fn poll_job(client: TogglClient, db: DatabaseConnection, poll_period: u64) {
|
||||
@@ -33,7 +33,7 @@ pub async fn poll_job(client: TogglClient, db: DatabaseConnection, poll_period:
|
||||
pub async fn perform_poll(
|
||||
client: &TogglClient,
|
||||
db: &DatabaseConnection,
|
||||
) -> beachhead::Result<usize> {
|
||||
) -> utils::Result<usize> {
|
||||
let now = chrono::Utc::now();
|
||||
let today_string = now
|
||||
.date_naive()
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use tokio::signal;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AppError(anyhow::Error);
|
||||
|
||||
// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into
|
||||
// `Result<_, AppError>`. That way you don't need to do that manually.
|
||||
impl<E> From<E> for AppError
|
||||
where
|
||||
E: Into<anyhow::Error>,
|
||||
{
|
||||
fn from(err: E) -> Self {
|
||||
Self(err.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
tracing::error!("{:?}", self);
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"An internal error occurred",
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T, E = AppError> = std::result::Result<T, E>;
|
||||
|
||||
pub async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
signal::ctrl_c()
|
||||
.await
|
||||
.expect("failed to install Ctrl+C handler");
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
let terminate = async {
|
||||
signal::unix::signal(signal::unix::SignalKind::terminate())
|
||||
.expect("failed to install signal handler")
|
||||
.recv()
|
||||
.await;
|
||||
};
|
||||
|
||||
#[cfg(not(unix))]
|
||||
let terminate = std::future::pending::<()>();
|
||||
|
||||
tokio::select! {
|
||||
_ = ctrl_c => {},
|
||||
_ = terminate => {},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user