Add DATABASE_CONNECTION option
This commit is contained in:
parent
580f80b521
commit
a85f6878ae
2 changed files with 21 additions and 36 deletions
38
README.md
38
README.md
|
|
@ -5,6 +5,16 @@
|
|||
|
||||
## 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:
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
- [ ] 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 tests
|
||||
|
|
|
|||
|
|
@ -13,20 +13,23 @@ fn main() {
|
|||
let rt = Runtime::new().unwrap();
|
||||
|
||||
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={}",
|
||||
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_PASSWORD").unwrap_or(String::from("root"))
|
||||
);
|
||||
),
|
||||
};
|
||||
|
||||
println!("Connection string: {}", db_connection_string);
|
||||
|
||||
rt.block_on(async {
|
||||
// Connect to the database.
|
||||
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...");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue