Skip to content

Commit 2808249

Browse files
authored
feat(voyager): refactor message to be generic over contained data (#1085)
this is in preparation for implementing block polling in the queue. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a search functionality to the app. - **Refactor** - Removed traits, macro definitions, and commented out type aliases and associated trait implementations in `data.rs`. - Altered declarations of exported entities, reorganized imports, updated function signatures, and refactored event handling logic in `event.rs`. - Modified `additionalSrcFilter` in `voyager.nix` to affect the logic for filtering additional source files. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 14b941d + 0947110 commit 2808249

25 files changed

+1848
-1972
lines changed

flake.nix

+4
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@
351351
nativeBuildInputs = [ config.treefmt.build.wrapper ]
352352
++ lib.attrsets.attrValues config.treefmt.build.programs;
353353
GOPRIVATE = "github.com/unionlabs/*";
354+
355+
shellHook = ''
356+
alias voy-send-msg='curl localhost:65534/msg -H "content-type: application/json" -d'
357+
'';
354358
};
355359

356360
treefmt =

lib/chain-utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<T: Clone> Pool<T> {
7171
const RETRY_SECONDS: u64 = 3;
7272

7373
tracing::warn!(
74-
"high traffic in queue of {}, ran out of items! trying again in {RETRY_SECONDS} seconds",
74+
"high traffic in pool of {}, ran out of items! trying again in {RETRY_SECONDS} seconds",
7575
std::any::type_name::<T>()
7676
);
7777

.sqlx/query-6a85593f1503d8c91d1226cd484d02f1cf40c9f4f81ff258025a70797a2b5c75.json lib/pg-queue/.sqlx/query-8d85587cf5dc38d8b3591b4d64b7ace960fdc1ebfee6c23124de1171000ae521.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pg-queue/src/lib.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,19 @@ impl<T: DeserializeOwned + Serialize + Unpin + Send + Sync> Queue<T> {
125125
.await?;
126126
tx.commit().await?;
127127
}
128-
ProcessFlow::Success(new_msgs) => {
129-
if !new_msgs.is_empty() {
130-
let new_ids = query!(
128+
ProcessFlow::Success(maybe_new_msg) => {
129+
if let Some(new_msg) = maybe_new_msg {
130+
let new_row = query!(
131131
"INSERT INTO queue (item)
132-
SELECT * FROM UNNEST($1::JSONB[])
132+
VALUES ($1::JSONB)
133133
RETURNING id",
134-
&*new_msgs
135-
.into_iter()
136-
.map(|t| serde_json::to_value(t).expect(
137-
"queue message should have infallible serialization"
138-
))
139-
.collect::<Vec<_>>(),
134+
serde_json::to_value(new_msg)
135+
.expect("queue message should have infallible serialization")
140136
)
141-
.fetch_all(tx.as_mut())
137+
.fetch_one(tx.as_mut())
142138
.await?;
143139

144-
for row in new_ids {
145-
tracing::debug!(id = row.id, "inserted new messages");
146-
}
140+
tracing::debug!(id = new_row.id, "inserted new message");
147141
}
148142

149143
tx.commit().await?;
@@ -164,7 +158,7 @@ impl<T: DeserializeOwned + Serialize + Unpin + Send + Sync> Queue<T> {
164158
}
165159

166160
pub enum ProcessFlow<T> {
167-
Success(Vec<T>),
161+
Success(Option<T>),
168162
Requeue,
169163
Fail(String),
170164
}

tools/sqlx-cli/sqlx-cli.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
version = "0.7.1";
2020
nativeBuildInputs = [ pkgs.pkg-config ];
2121

22-
buildPhase = "cargo build --release --locked --offline -p ${name}";
22+
buildPhase = "cargo build --release --locked --offline -p ${name} --bin cargo-sqlx";
2323
installPhase = ''
2424
mkdir -p $out/bin
25-
mv target/release/sqlx $out/bin/sqlx
25+
mv target/release/cargo-sqlx $out/bin/cargo-sqlx
2626
'';
2727

2828
buildInputs = [ rust.toolchains.nightly pkgs.openssl ];
2929

3030
src = srcWithVendoredSources { inherit name; originalSrc = "${sqlx}"; };
3131

32-
meta.mainProgram = "sqlx";
32+
meta.mainProgram = "cargo-sqlx";
3333
};
3434
};
3535
}

voyager/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![recursion_limit = "256"]
2-
#![feature(trait_alias, extract_if)]
1+
#![feature(trait_alias)]
32
// #![warn(clippy::pedantic)]
43
#![allow(
54
// required due to return_position_impl_trait_in_trait false positives

0 commit comments

Comments
 (0)