Skip to content

Commit 16580c5

Browse files
Nemo157jyn514
authored andcommitted
Add commands to read/write the last-seen-reference
1 parent f2aad30 commit 16580c5

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/bin/cratesfyi.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ enum QueueSubcommand {
212212
#[command(subcommand)]
213213
subcommand: PrioritySubcommand,
214214
},
215+
216+
/// Get the registry watcher's last seen reference
217+
GetLastSeenReference,
218+
219+
/// Set the register watcher's last seen reference
220+
SetLastSeenReference {
221+
reference: crates_index_diff::gix::ObjectId,
222+
},
215223
}
216224

217225
impl QueueSubcommand {
@@ -228,6 +236,18 @@ impl QueueSubcommand {
228236
ctx.config()?.registry_url.as_deref(),
229237
)?,
230238

239+
Self::GetLastSeenReference => {
240+
if let Some(reference) = ctx.build_queue()?.last_seen_reference()? {
241+
println!("Last seen reference: {reference}");
242+
} else {
243+
println!("No last seen reference available");
244+
}
245+
}
246+
247+
Self::SetLastSeenReference { reference } => {
248+
ctx.build_queue()?.set_last_seen_reference(reference)?;
249+
}
250+
231251
Self::DefaultPriority { subcommand } => subcommand.handle_args(ctx)?,
232252
}
233253
Ok(())

src/build_queue.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl BuildQueue {
5858
Ok(None)
5959
}
6060

61-
fn set_last_seen_reference(&self, oid: crates_index_diff::gix::ObjectId) -> Result<()> {
61+
pub fn set_last_seen_reference(&self, oid: crates_index_diff::gix::ObjectId) -> Result<()> {
6262
let mut conn = self.db.get()?;
6363
set_config(
6464
&mut conn,
@@ -77,7 +77,7 @@ impl BuildQueue {
7777
registry: Option<&str>,
7878
) -> Result<()> {
7979
self.db.get()?.execute(
80-
"INSERT INTO queue (name, version, priority, registry)
80+
"INSERT INTO queue (name, version, priority, registry)
8181
VALUES ($1, $2, $3, $4)
8282
ON CONFLICT (name, version) DO UPDATE
8383
SET priority = EXCLUDED.priority,
@@ -104,10 +104,10 @@ impl BuildQueue {
104104

105105
pub(crate) fn pending_count_by_priority(&self) -> Result<HashMap<i32, usize>> {
106106
let res = self.db.get()?.query(
107-
"SELECT
108-
priority,
109-
COUNT(*)
110-
FROM queue
107+
"SELECT
108+
priority,
109+
COUNT(*)
110+
FROM queue
111111
WHERE attempt < $1
112112
GROUP BY priority",
113113
&[&self.max_attempts],
@@ -154,9 +154,9 @@ impl BuildQueue {
154154
.query_opt(
155155
"SELECT id
156156
FROM queue
157-
WHERE
158-
attempt < $1 AND
159-
name = $2 AND
157+
WHERE
158+
attempt < $1 AND
159+
name = $2 AND
160160
version = $3
161161
",
162162
&[&self.max_attempts, &name, &version],
@@ -183,7 +183,7 @@ impl BuildQueue {
183183
FROM queue
184184
WHERE attempt < $1
185185
ORDER BY priority ASC, attempt ASC, id ASC
186-
LIMIT 1
186+
LIMIT 1
187187
FOR UPDATE SKIP LOCKED",
188188
&[&self.max_attempts],
189189
)?
@@ -482,7 +482,7 @@ mod tests {
482482
let mut conn = env.db().conn();
483483
conn.execute(
484484
"
485-
INSERT INTO queue (name, version, priority, attempt )
485+
INSERT INTO queue (name, version, priority, attempt )
486486
VALUES ('failed_crate', '0.1.1', 0, 99)",
487487
&[],
488488
)?;
@@ -496,7 +496,7 @@ mod tests {
496496
let row = conn
497497
.query_opt(
498498
"SELECT priority, attempt
499-
FROM queue
499+
FROM queue
500500
WHERE name = $1 AND version = $2",
501501
&[&"failed_crate", &"0.1.1"],
502502
)?

0 commit comments

Comments
 (0)