12
12
13
13
use crate :: metrics:: macros:: metrics;
14
14
use crate :: schema:: { background_jobs, crates, versions} ;
15
- use crate :: util:: diesel:: Conn ;
16
15
use crate :: util:: errors:: AppResult ;
17
16
use diesel:: { dsl:: count_star, prelude:: * } ;
17
+ use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
18
18
use prometheus:: { proto:: MetricFamily , IntGauge , IntGaugeVec } ;
19
19
20
20
metrics ! {
@@ -32,11 +32,14 @@ metrics! {
32
32
}
33
33
34
34
impl ServiceMetrics {
35
- pub ( crate ) fn gather ( & self , conn : & mut impl Conn ) -> AppResult < Vec < MetricFamily > > {
35
+ pub ( crate ) async fn gather (
36
+ & self ,
37
+ conn : & mut AsyncPgConnection ,
38
+ ) -> AppResult < Vec < MetricFamily > > {
36
39
self . crates_total
37
- . set ( crates:: table. select ( count_star ( ) ) . first ( conn) ?) ;
40
+ . set ( crates:: table. select ( count_star ( ) ) . first ( conn) . await ?) ;
38
41
self . versions_total
39
- . set ( versions:: table. select ( count_star ( ) ) . first ( conn) ?) ;
42
+ . set ( versions:: table. select ( count_star ( ) ) . first ( conn) . await ?) ;
40
43
41
44
let background_jobs = background_jobs:: table
42
45
. group_by ( ( background_jobs:: job_type, background_jobs:: priority) )
@@ -45,7 +48,8 @@ impl ServiceMetrics {
45
48
background_jobs:: priority,
46
49
count_star ( ) ,
47
50
) )
48
- . load :: < ( String , i16 , i64 ) > ( conn) ?;
51
+ . load :: < ( String , i16 , i64 ) > ( conn)
52
+ . await ?;
49
53
50
54
self . background_jobs . reset ( ) ;
51
55
for ( job, priority, count) in background_jobs {
0 commit comments