Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
36060 amit 1
package com.smartdukaan.cron.scheduled;
2
 
3
import com.spice.profitmandi.service.mail.MailOutboxService;
4
import org.apache.logging.log4j.LogManager;
5
import org.apache.logging.log4j.Logger;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.beans.factory.annotation.Value;
8
import org.springframework.scheduling.annotation.Scheduled;
9
import org.springframework.stereotype.Component;
10
 
11
@Component
12
public class MailOutboxScheduler {
13
 
14
    private static final Logger LOGGER = LogManager.getLogger(MailOutboxScheduler.class);
15
 
16
    @Value("${prod:false}")
17
    private boolean isProd;
18
 
19
    @Autowired
20
    private MailOutboxService mailOutboxService;
21
 
22
    @Scheduled(cron = "0 */2 * * * *")
23
    public void processPendingMails() {
24
        if (!isProd) {
25
            return;
26
        }
27
        try {
28
            mailOutboxService.processPendingMails();
29
        } catch (Exception e) {
30
            LOGGER.error("Error processing pending mails", e);
31
        }
32
    }
33
 
34
    @Scheduled(cron = "0 0 3 * * *")
35
    public void cleanupOldMails() {
36
        if (!isProd) {
37
            return;
38
        }
39
        try {
40
            mailOutboxService.cleanupOldMails(30);
41
        } catch (Exception e) {
42
            LOGGER.error("Error cleaning up old mails", e);
43
        }
44
    }
45
}