Add DATABASE_CONNECTION option

This commit is contained in:
dolphinau 2025-08-27 21:36:23 +02:00
parent 580f80b521
commit a85f6878ae
No known key found for this signature in database
2 changed files with 21 additions and 36 deletions

View file

@ -5,6 +5,16 @@
## Usage ## Usage
### Using nix
```nix
nix develop # to get the dev dependencies
nix build
nix run -- /tmp/rss/
```
### Using podman
Use the `justfile` to run commands: Use the `justfile` to run commands:
```bash ```bash
@ -12,35 +22,7 @@ just init # Will init the database, and build the app image
just run # Will run the lwn-sub-snoozer to update the database and the RSS file just run # Will run the lwn-sub-snoozer to update the database and the RSS file
``` ```
## Nix setup
For my server, I have the following setup:
```nix
systemd.timers."rssify-update" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "12h";
Unit = "rssify-update.service";
};
};
systemd.services."rssify-update" = {
script = ''
${pkgs.rssify}/bin/echo "Hello World"
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
```
## TODO ## TODO
- [ ] Nix service with timer
- [ ] Better path managment, with env variable in Dockerfile
- [ ] Clean repo
- [ ] Add volume to the db to store it if it crashes - [ ] Add volume to the db to store it if it crashes
- [ ] Add tests - [ ] Add tests

View file

@ -13,20 +13,23 @@ fn main() {
let rt = Runtime::new().unwrap(); let rt = Runtime::new().unwrap();
let args = Cli::parse(); let args = Cli::parse();
let db_connection_string = &format!( let db_connection_string = match env::var("DATABASE_CONNECTION") {
Ok(s) => s,
_ => format!(
"host={} dbname={} user={} password={}", "host={} dbname={} user={} password={}",
env::var("POSTGRES_HOST").unwrap_or(String::from("localhost")), env::var("POSTGRES_HOST").unwrap_or(String::from("localhost")),
env::var("POSTGRES_USER").unwrap_or(String::from("root")), env::var("POSTGRES_USER").unwrap_or(String::from("root")),
env::var("POSTGRES_USER").unwrap_or(String::from("root")), env::var("POSTGRES_USER").unwrap_or(String::from("root")),
env::var("POSTGRES_PASSWORD").unwrap_or(String::from("root")) env::var("POSTGRES_PASSWORD").unwrap_or(String::from("root"))
); ),
};
println!("Connection string: {}", db_connection_string); println!("Connection string: {}", db_connection_string);
rt.block_on(async { rt.block_on(async {
// Connect to the database. // Connect to the database.
if let Ok((client, connection)) = if let Ok((client, connection)) =
tokio_postgres::connect(db_connection_string, tokio_postgres::NoTls).await tokio_postgres::connect(&db_connection_string, tokio_postgres::NoTls).await
{ {
println!("Working..."); println!("Working...");