Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates, development environment #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ members = ["sqlxmq_macros", "sqlxmq_stress"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sqlx = { version = "0.7.1", features = ["postgres", "chrono", "uuid"] }
tokio = { version = "1.8.3", features = ["full"] }
dotenv = "0.15.0"
chrono = "0.4.19"
uuid = { version = "1.1.2", features = ["v4"] }
log = "0.4.14"
serde_json = "1.0.64"
serde = "1.0.124"
sqlx = { version = "~0.8.1", features = ["postgres", "chrono", "uuid"] }
tokio = { version = "~1.38", features = ["full"] }
dotenvy = "~0.15.7"
chrono = "~0.4.19"
uuid = { version = "~1.1", features = ["v4"] }
log = "~0.4"
serde_json = "~1.0"
serde = "~1.0"
sqlxmq_macros = { version = "0.5.0", path = "sqlxmq_macros" }
anymap2 = "0.13.0"
anymap2 = "~0.13"

[features]
default = ["runtime-tokio-native-tls"]
runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls"]
runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"]

[dev-dependencies]
dotenv = "0.15.0"
dotenvy = "0.15.0"
pretty_env_logger = "0.4.0"
futures = "0.3.13"
tokio = { version = "1", features = ["full"] }
3 changes: 3 additions & 0 deletions devsupport/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
db/
db_sockets/
!db_sockets/.gitkeep
Empty file added devsupport/db_sockets/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions devsupport/run_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env bash

set -e
devsupport=$(realpath $(dirname $0))
if [ ! -d "$PGDATA" ]; then
initdb --no-instructions
fi
exec postgres -c listen_addresses= -c unix_socket_directories="${devsupport}/db_sockets"
4 changes: 4 additions & 0 deletions devsupport/setup_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

sqlx database create
sqlx migrate run
7 changes: 7 additions & 0 deletions envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export db_socket_path=$(echo $(pwd)/devsupport/db_sockets)
export PGDATA="$(pwd)/devsupport/db"
export DATABASE_URL="postgres:///sqlxmq?host=$db_socket_path&sslmode=disable"
# export SQLX_OFFLINE=yes

session_name sqlxmq
use lorri
2 changes: 1 addition & 1 deletion examples/graceful-shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::time;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::dotenv().ok();
dotenvy::dotenv().ok();
let db = sqlx::PgPool::connect(&std::env::var("DATABASE_URL").unwrap()).await?;

sleep.builder().set_json(&5u64)?.spawn(&db).await?;
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
description = "sqlxmq is a message queue built by Diggsey on rust sqlx";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/24.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import "${nixpkgs}" {
inherit system;
});

runDeps = with pkgs; [
openssl
];

buildDeps = with pkgs; [
pkg-config
] ++ runDeps;
in rec {
devShells.devShell.${system} = pkgs.mkShell {
buildInputs = with pkgs; [
cargo
cargo-expand
rustc
rust-analyzer
clippy

postgresql
sqlx-cli
] ++ buildDeps;
};
devShells.default = devShells.devShell.${system};
});
}
2 changes: 1 addition & 1 deletion sqlxmq_stress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn schedule_tasks(num_jobs: usize, interval: Duration, pool: Pool<Postgres

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let _ = dotenv::dotenv();
let _ = dotenvy::dotenv();

let pool = Pool::connect(&env::var("DATABASE_URL")?).await?;

Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ mod tests {
use tokio::sync::{Mutex, MutexGuard};
use tokio::task;

// field 0 is never read, but its drop is important
#[allow(dead_code)]
struct TestGuard<T>(MutexGuard<'static, ()>, T);

impl<T> Deref for TestGuard<T> {
Expand All @@ -294,7 +296,7 @@ mod tests {

let guard = TEST_MUTEX.lock().await;

let _ = dotenv::dotenv();
let _ = dotenvy::dotenv();

INIT_LOGGER.call_once(pretty_env_logger::init);

Expand Down