chore: update nats -> async nats

This commit is contained in:
Kasper Juul Hermansen 2025-03-26 21:25:12 +01:00
parent b7cc1b32c0
commit cf0e745b5b
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
11 changed files with 664 additions and 630 deletions

1233
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,32 +11,32 @@ tracing-subscriber.workspace = true
clap.workspace = true clap.workspace = true
dotenv.workspace = true dotenv.workspace = true
axum.workspace = true axum.workspace = true
prost = "0.13.2" prost = "0.13"
tonic = { version = "0.12.2", features = ["tls", "tls-native-roots"] } tonic = { version = "0.12", features = ["tls", "tls-native-roots"] }
uuid = { version = "1.7.0", features = ["v7", "v4"] } uuid = { version = "1.7", features = ["v7", "v4"] }
async-trait = "0.1.77" async-trait = "0.1"
aws-config = { version = "1.5.5", features = ["behavior-version-latest"] } aws-config = { version = "1.5.5", features = ["behavior-version-latest"] }
aws-sdk-s3 = { version = "1.48.0", features = ["behavior-version-latest"] } aws-sdk-s3 = { version = "1.48.0", features = ["behavior-version-latest"] }
serde = { version = "1.0.196", features = ["derive"] } serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113" serde_json = "1"
nats = "0.25.0" async-nats = "0.40.0"
walkdir = "2.4.0" walkdir = "2.4.0"
tar = "0.4.40" tar = "0.4.40"
tokio-stream = { version = "0.1.15", features = ["full"] } tokio-stream = { version = "0.1.15", features = ["full"] }
rand = "0.9.0" rand = "0.8.5"
sqlx = { version = "0.8.0", features = [ sqlx = { version = "0.8.0", features = [
"postgres", "postgres",
"runtime-tokio", "runtime-tokio",
"uuid", "uuid",
"chrono", "chrono",
] } ] }
chrono = "0.4.34" chrono = "0.4"
git2 = "0.20.0" git2 = "0.20"
rustls = { version = "0.23.12" } rustls = { version = "0.23" }
[build-dependencies] [build-dependencies]
tonic-build = "0.12.0" tonic-build = "0.12.0"
[dev-dependencies] [dev-dependencies]
lazy_static = "1.4.0" lazy_static = "1.4"
reqwest = "0.12.0" reqwest = "0.12"

View File

@ -1,6 +1,6 @@
use std::{ops::Deref, sync::Arc}; use std::{ops::Deref, sync::Arc};
use sqlx::{PgPool, Postgres}; use sqlx::PgPool;
use crate::services::{ use crate::services::{
archive::Archive, archive::Archive,

View File

@ -1,5 +1,5 @@
use anyhow::Context; use anyhow::Context;
use sqlx::{PgPool, Postgres}; use sqlx::PgPool;
pub async fn get_database() -> anyhow::Result<PgPool> { pub async fn get_database() -> anyhow::Result<PgPool> {
tracing::trace!("initializing database"); tracing::trace!("initializing database");

View File

@ -4,17 +4,20 @@ use anyhow::Context;
#[derive(Clone)] #[derive(Clone)]
pub struct Nats { pub struct Nats {
nats: Arc<nats::asynk::Connection>, nats: Arc<async_nats::Client>,
} }
impl Nats { impl Nats {
pub async fn new() -> anyhow::Result<Self> { pub async fn new() -> anyhow::Result<Self> {
let nats = nats::asynk::Options::with_user_pass( let nats = async_nats::connect_with_options(
&std::env::var("NATS_USERNAME").context("NATS_USERNAME was not found")?, std::env::var("NATS_URL").context("NATS_URL was not found")?,
&std::env::var("NATS_PASSWORD").context("NATS_PASSWORD was not found")?, async_nats::ConnectOptions::new()
.user_and_password(
std::env::var("NATS_USERNAME").context("NATS_USERNAME was not found")?,
std::env::var("NATS_PASSWORD").context("NATS_PASSWORD was not found")?,
)
.name(std::env!("CARGO_PKG_NAME")),
) )
.with_name(std::env!("CARGO_PKG_NAME"))
.connect(std::env::var("NATS_URL").context("NATS_URL was not found")?)
.await?; .await?;
Ok(Self { Ok(Self {
@ -24,7 +27,7 @@ impl Nats {
} }
impl std::ops::Deref for Nats { impl std::ops::Deref for Nats {
type Target = nats::asynk::Connection; type Target = async_nats::Client;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.nats &self.nats

View File

@ -1,8 +1,8 @@
use std::{env::temp_dir, fmt::Display, net::SocketAddr}; use std::{env::temp_dir, net::SocketAddr};
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use tonic::{service::interceptor, transport::Server}; use tonic::transport::Server;
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::{

View File

@ -2,7 +2,7 @@
pub struct Archive {} pub struct Archive {}
use std::{ use std::{
io::{Bytes, Cursor}, io::Cursor,
path::Path, path::Path,
}; };

View File

@ -15,7 +15,7 @@ impl DomainEvents {
tracing::trace!("publish events: {}", event); tracing::trace!("publish events: {}", event);
self.nats self.nats
.publish("flux_releaser.domain_events", event) .publish("flux_releaser.domain_events", event.to_string().into())
.await?; .await?;
Ok(()) Ok(())

View File

@ -1,8 +1,7 @@
use tonic::transport::Channel;
use crate::{ use crate::{
app::infra::grpc::FluxReleaserGrpcClient, app::infra::grpc::FluxReleaserGrpcClient,
grpc::gen::{flux_releaser_client::FluxReleaserClient, UploadArtifactRequest}, grpc::gen::UploadArtifactRequest,
}; };
use super::{archive::ArchiveFile, release_manager::models::UploadArtifactID}; use super::{archive::ArchiveFile, release_manager::models::UploadArtifactID};

View File

@ -1,6 +1,6 @@
use serde::Serialize; use serde::Serialize;
use crate::services::archive::{Archive, ArchiveFile}; use crate::services::archive::ArchiveFile;
use crate::services::artifacts_db::{AddCommitArtifact, GetLatestArtifact}; use crate::services::artifacts_db::{AddCommitArtifact, GetLatestArtifact};
use crate::services::file_store::FileStore; use crate::services::file_store::FileStore;

View File

@ -1,6 +1,3 @@
use flux_releaser::services::{
archive::Archive, file_reader::FileReader, flux_local_cluster::FluxLocalClusterManager,
};
#[tokio::test] #[tokio::test]
async fn can_package_files() -> anyhow::Result<()> { async fn can_package_files() -> anyhow::Result<()> {