• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 26773559161

01 Jun 2026 06:21PM UTC coverage: 63.376% (-0.01%) from 63.389%
26773559161

push

github

web-flow
TRUNK-6429: Create application events for service method calls and entity changes (#6084)

272 of 504 new or added lines in 27 files covered. (53.97%)

5 existing lines in 2 files now uncovered.

23598 of 37235 relevant lines covered (63.38%)

0.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.46
/api/src/main/java/org/openmrs/event/outbox/tasks/OutboxCleanupTaskHandler.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.event.outbox.tasks;
11

12
import org.hibernate.Session;
13
import org.hibernate.SessionFactory;
14
import org.openmrs.scheduler.TaskContext;
15
import org.openmrs.scheduler.TaskHandler;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18
import org.springframework.beans.factory.annotation.Value;
19
import org.springframework.stereotype.Component;
20
import org.springframework.transaction.annotation.Transactional;
21

22
import javax.persistence.Query;
23
import java.time.Duration;
24
import java.time.Instant;
25
import java.util.Date;
26

27
/**
28
 * @since 2.9.x
29
 */
30
@Component
31
public class OutboxCleanupTaskHandler implements TaskHandler<OutboxCleanupTaskData> {
32

33
        private static final Logger log = LoggerFactory.getLogger(OutboxCleanupTaskHandler.class);
1✔
34
        public final Duration cleanupOlderThan;
35
        
36
        private final SessionFactory sessionFactory;
37

38
        public OutboxCleanupTaskHandler(SessionFactory sessionFactory,
39
                                        @Value("${outboxevent.cleanup.olderThan:7}") int cleanupOlderThan) {
1✔
40
                this.sessionFactory = sessionFactory;
1✔
41
                this.cleanupOlderThan = Duration.ofDays(cleanupOlderThan);
1✔
42
        }
1✔
43

44
        @Override
45
        @Transactional
46
        public void execute(OutboxCleanupTaskData taskData, TaskContext taskContext) throws Exception {
NEW
47
                Session session = sessionFactory.getCurrentSession();
×
48

NEW
49
                Date threshold = Date.from(Instant.now().minus(cleanupOlderThan));
×
50

NEW
51
                Query query = session.createQuery(
×
52
                                "delete from OutboxEvent where status = 'COMPLETED' and dateChanged <= :threshold");
NEW
53
                query.setParameter("threshold", threshold);
×
54

NEW
55
                int deletedCount = query.executeUpdate();
×
NEW
56
                if (deletedCount > 0) {
×
NEW
57
                        log.debug("Deleted {} completed outbox items older than {} days", deletedCount, cleanupOlderThan.toDays());
×
58
                }
NEW
59
        }
×
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc