@@ -3,6 +3,7 @@ use crate::schema::{background_jobs, crates};
3
3
use crate :: worker:: jobs;
4
4
use anyhow:: Result ;
5
5
use crates_io_worker:: BackgroundJob ;
6
+ use diesel:: dsl:: exists;
6
7
use diesel:: prelude:: * ;
7
8
use secrecy:: { ExposeSecret , SecretString } ;
8
9
@@ -30,7 +31,11 @@ pub enum Command {
30
31
#[ arg( ) ]
31
32
name : String ,
32
33
} ,
33
- SyncAdmins ,
34
+ SyncAdmins {
35
+ /// Force a sync even if one is already in progress
36
+ #[ arg( long) ]
37
+ force : bool ,
38
+ } ,
34
39
}
35
40
36
41
pub fn run ( command : Command ) -> Result < ( ) > {
@@ -59,7 +64,26 @@ pub fn run(command: Command) -> Result<()> {
59
64
} => {
60
65
jobs:: DumpDb :: new ( database_url. expose_secret ( ) , target_name) . enqueue ( conn) ?;
61
66
}
62
- Command :: SyncAdmins => {
67
+ Command :: SyncAdmins { force } => {
68
+ if !force {
69
+ // By default, we don't want to enqueue a sync if one is already
70
+ // in progress. If a sync fails due to e.g. an expired pinned
71
+ // certificate we don't want to keep adding new jobs to the
72
+ // queue, since the existing job will be retried until it
73
+ // succeeds.
74
+
75
+ let query = background_jobs:: table
76
+ . filter ( background_jobs:: job_type. eq ( jobs:: SyncAdmins :: JOB_NAME ) ) ;
77
+
78
+ if diesel:: select ( exists ( query) ) . get_result ( conn) ? {
79
+ info ! (
80
+ "Did not enqueue {}, existing job already in progress" ,
81
+ jobs:: SyncAdmins :: JOB_NAME
82
+ ) ;
83
+ return Ok ( ( ) ) ;
84
+ }
85
+ }
86
+
63
87
jobs:: SyncAdmins . enqueue ( conn) ?;
64
88
}
65
89
Command :: DailyDbMaintenance => {
0 commit comments