Skip to content

Commit bbe0f23

Browse files
committed
worker::git: Read yanked status from database
This avoids out-of-order issues when previous tasks failed and are retried at the end of the queue.
1 parent 46d96d3 commit bbe0f23

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/controllers/version/yank.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn modify_yank(req: &mut dyn RequestExt, yanked: bool) -> EndpointResult {
6161

6262
insert_version_owner_action(&conn, version.id, user.id, api_token_id, action)?;
6363

64-
worker::yank(krate.name, version.num, yanked).enqueue(&conn)?;
64+
worker::sync_yanked(krate.name, version.num).enqueue(&conn)?;
6565

6666
ok_true()
6767
}

src/worker/git.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::background_jobs::Environment;
22
use crate::git::{Crate, Credentials};
3+
use crate::schema;
4+
use anyhow::Context;
35
use chrono::Utc;
6+
use diesel::prelude::*;
47
use std::fs::{self, OpenOptions};
58
use std::io::prelude::*;
69
use swirl::PerformError;
@@ -28,12 +31,24 @@ pub fn add_crate(env: &Environment, krate: Crate) -> Result<(), PerformError> {
2831
/// `true` or `false`, write all the lines back out, and commit and
2932
/// push the changes.
3033
#[swirl::background_job]
31-
pub fn yank(
34+
pub fn sync_yanked(
3235
env: &Environment,
36+
conn: &PgConnection,
3337
krate: String,
3438
version_num: String,
35-
yanked: bool,
3639
) -> Result<(), PerformError> {
40+
trace!(?krate, ?version_num, "Load yanked status from database");
41+
42+
let yanked: bool = schema::versions::table
43+
.inner_join(schema::crates::table)
44+
.filter(schema::crates::name.eq(&krate))
45+
.filter(schema::versions::num.eq(&version_num))
46+
.select(schema::versions::yanked)
47+
.get_result(conn)
48+
.context("Failed to load yanked status from database")?;
49+
50+
trace!(?krate, ?version_num, yanked);
51+
3752
let repo = env.lock_index()?;
3853
let dst = repo.index_file(&krate);
3954

src/worker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ mod update_downloads;
1111

1212
pub use daily_db_maintenance::daily_db_maintenance;
1313
pub use dump_db::dump_db;
14-
pub use git::{add_crate, squash_index, yank};
14+
pub use git::{add_crate, squash_index, sync_yanked};
1515
pub use readmes::render_and_upload_readme;
1616
pub use update_downloads::update_downloads;

0 commit comments

Comments
 (0)