@@ -8,17 +8,12 @@ use diesel::dsl::now;
8
8
use diesel:: prelude:: * ;
9
9
use std:: sync:: Arc ;
10
10
11
- /// The threshold in days for the expiry notification.
11
+ /// The threshold for the expiry notification.
12
12
const EXPIRY_THRESHOLD : chrono:: TimeDelta = chrono:: TimeDelta :: days ( 3 ) ;
13
13
14
- /// The maximum number of tokens to check.
15
- /// To avoid sending too many emails and submitting to many transactions, we limit the number of
16
- /// tokens to check.
14
+ /// The maximum number of tokens to check per run.
17
15
const MAX_ROWS : i64 = 10000 ;
18
16
19
- /// A job responsible for monitoring the status of a token.
20
- /// It checks if the token is about to reach its expiry date.
21
- /// If the token is about to expire, the job triggers a notification.
22
17
#[ derive( Default , Serialize , Deserialize , Debug ) ]
23
18
pub struct SendTokenExpiryNotifications ;
24
19
@@ -40,7 +35,7 @@ impl BackgroundJob for SendTokenExpiryNotifications {
40
35
}
41
36
}
42
37
43
- // Check if the token is about to expire and send a notification if it is .
38
+ /// Find tokens that are about to expire and send notifications to their owners .
44
39
fn check ( emails : & Emails , conn : & mut PgConnection ) -> anyhow:: Result < ( ) > {
45
40
info ! ( "Checking if tokens are about to expire" ) ;
46
41
let before = chrono:: Utc :: now ( ) + EXPIRY_THRESHOLD ;
@@ -57,6 +52,7 @@ fn check(emails: &Emails, conn: &mut PgConnection) -> anyhow::Result<()> {
57
52
Ok ( ( ) )
58
53
}
59
54
55
+ /// Send an email to the user associated with the token.
60
56
fn handle_expiring_token (
61
57
conn : & mut PgConnection ,
62
58
token : & ApiToken ,
0 commit comments