-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start implementing free wisdoms route nad daily rotator worker
- Loading branch information
1 parent
94b0a9c
commit 1046b53
Showing
12 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "worker" | ||
name = "worker_wisdoms_checker" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "worker_wisdoms_daily_rotator" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tokio = { version = "1.35.1", features = ["full"] } | ||
serde = { version = "1.0.194", features = ["derive"] } | ||
serde_json = "1.0.112" | ||
dotenv = "0.15.0" | ||
sqlx = { version = "0.7.4", features = ["postgres","runtime-tokio-rustls"] } | ||
base64="0.22.1" | ||
teloxide = { version = "0.12", features = ["macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::time::Duration; | ||
|
||
use sqlx::PgPool; | ||
|
||
pub async fn worker_thread(_pool: PgPool) { | ||
loop { | ||
dbg!("Rotating..."); | ||
tokio::time::sleep(Duration::from_secs(5)).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pub type Result<T> = core::result::Result<T, Error>; | ||
|
||
use sqlx::postgres::PgPoolOptions; | ||
|
||
pub type Database = sqlx::Pool<sqlx::Postgres>; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
FailedConnectingToDatabase { error: String }, | ||
} | ||
|
||
impl From<sqlx::Error> for Error { | ||
fn from(value: sqlx::Error) -> Self { | ||
Self::FailedConnectingToDatabase { | ||
error: value.to_string(), | ||
} | ||
} | ||
} | ||
|
||
pub async fn connect(db_url: &str) -> Result<Database> { | ||
let pool: Database = PgPoolOptions::new() | ||
// TODO: Max connections! Dynamic? | ||
.max_connections(5) | ||
.connect(db_url) | ||
.await?; | ||
Ok(pool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
mod daily_rotator; | ||
mod db_connect; | ||
|
||
use std::env; | ||
|
||
use daily_rotator::worker_thread; | ||
use db_connect::connect; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let _ = dotenv::dotenv(); | ||
|
||
let database_url = env::var("DATABASE_URL") | ||
.unwrap_or_else(|_| panic!("Missing required environment variable: {}", "DATABASE_URL")); | ||
|
||
let db = connect(database_url.as_str()).await.unwrap(); | ||
|
||
tokio::spawn(worker_thread(db)).await.unwrap(); | ||
} |