-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(svc): resolve cluster name id op (#751)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
- Loading branch information
1 parent
27ab366
commit 58200ec
Showing
7 changed files
with
123 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "cluster-resolve-for-name-id" | ||
version = "0.0.1" | ||
edition = "2018" | ||
authors = ["Rivet Gaming, LLC <developer@rivet.gg>"] | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
chirp-client = { path = "../../../../../lib/chirp/client" } | ||
prost = "0.10" | ||
rivet-operation = { path = "../../../../../lib/operation/core" } | ||
|
||
[dependencies.sqlx] | ||
version = "0.7" | ||
default-features = false | ||
|
||
[dev-dependencies] | ||
chirp-worker = { path = "../../../../../lib/chirp/worker" } |
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 @@ | ||
[service] | ||
name = "cluster-resolve-for-name-id" | ||
|
||
[runtime] | ||
kind = "rust" | ||
|
||
[operation] | ||
|
||
[databases] | ||
db-cluster = {} |
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,35 @@ | ||
use proto::backend::pkg::*; | ||
use rivet_operation::prelude::*; | ||
|
||
#[derive(sqlx::FromRow)] | ||
struct Cluster { | ||
cluster_id: Uuid, | ||
name_id: String, | ||
} | ||
|
||
#[operation(name = "cluster-resolve-for-name-id")] | ||
pub async fn handle( | ||
ctx: OperationContext<cluster::resolve_for_name_id::Request>, | ||
) -> GlobalResult<cluster::resolve_for_name_id::Response> { | ||
let clusters = sql_fetch_all!( | ||
[ctx, Cluster] | ||
" | ||
SELECT | ||
cluster_id, | ||
name_id | ||
FROM db_cluster.clusters | ||
WHERE | ||
name_id = ANY($1) | ||
", | ||
&ctx.name_ids, | ||
) | ||
.await? | ||
.into_iter() | ||
.map(|dc| cluster::resolve_for_name_id::response::Cluster { | ||
cluster_id: Some(dc.cluster_id.into()), | ||
name_id: dc.name_id, | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok(cluster::resolve_for_name_id::Response { clusters }) | ||
} |
29 changes: 29 additions & 0 deletions
29
svc/pkg/cluster/ops/resolve-for-name-id/tests/integration.rs
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,29 @@ | ||
use chirp_worker::prelude::*; | ||
use proto::backend::{self, pkg::*}; | ||
|
||
#[worker_test] | ||
async fn empty(ctx: TestCtx) { | ||
let cluster_id = Uuid::new_v4(); | ||
let name_id = util::faker::ident(); | ||
|
||
msg!([ctx] cluster::msg::create(cluster_id) -> cluster::msg::create_complete { | ||
cluster_id: Some(cluster_id.into()), | ||
name_id: name_id.clone(), | ||
owner_team_id: None, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let res = op!([ctx] cluster_resolve_for_name_id { | ||
name_ids: vec![name_id], | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let cluster = res.clusters.first().expect("cluster not found"); | ||
assert_eq!( | ||
cluster_id, | ||
cluster.cluster_id.unwrap().as_uuid(), | ||
"wrong cluster returned" | ||
); | ||
} |
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 @@ | ||
syntax = "proto3"; | ||
|
||
package rivet.backend.pkg.cluster.resolve_for_name_id; | ||
|
||
import "proto/common.proto"; | ||
import "proto/backend/cluster.proto"; | ||
|
||
message Request { | ||
repeated string name_ids = 1; | ||
} | ||
|
||
message Response { | ||
message Cluster { | ||
rivet.common.Uuid cluster_id = 1; | ||
string name_id = 2; | ||
} | ||
|
||
repeated Cluster clusters = 1; | ||
} |