• 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

87.5
/api/src/main/java/org/openmrs/event/outbox/tasks/OutboxTaskSchedulerInitializer.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.openmrs.api.context.Context;
13
import org.openmrs.event.outbox.OutboxEventRegistry;
14
import org.openmrs.scheduler.SchedulerService;
15
import org.openmrs.util.PrivilegeConstants;
16
import org.springframework.beans.factory.SmartInitializingSingleton;
17
import org.springframework.stereotype.Component;
18

19
import java.time.Duration;
20

21
/**
22
 * @since 2.9.x
23
 */
24
@Component
25
public class OutboxTaskSchedulerInitializer implements SmartInitializingSingleton {
26
        
27
        public static final String OUTBOX_POLLER_TASK_NAME = "Transactional Outbox Poller";
28
        public static final String OUTBOX_POLLER_TASK_UUID = "bc2739ac-5bf3-4ecd-8e11-d383d53695bb";
29
        public static final String OUTBOX_CLEANUP_TASK_NAME = "Transactional Outbox Cleanup";
30
        public static final String OUTBOX_CLEANUP_TASK_UUID = "a0c11918-0aba-46bf-a7c6-7b0cc47e7323";
31

32
        private final SchedulerService schedulerService;
33
        
34
        private final OutboxEventRegistry outboxEventRegistry;
35

36
        public OutboxTaskSchedulerInitializer(SchedulerService schedulerService, OutboxEventRegistry outboxEventRegistry) {
1✔
37
                this.schedulerService = schedulerService;
1✔
38
                this.outboxEventRegistry = outboxEventRegistry;
1✔
39
        }
1✔
40

41
        @Override
42
        public void afterSingletonsInstantiated() {
43
                try {
44
                        if (!Context.isSessionOpen()) {
1✔
45
                                Context.openSession();
1✔
46
                        }
47
                        Context.addProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER);
1✔
48
                        
49
                        if (outboxEventRegistry.hasOutboxListeners()) {
1✔
50
                                // Schedule the outbox polling task to run recurrently in the background
51
                                schedulerService.scheduleRecurrently(
1✔
52
                                        OUTBOX_POLLER_TASK_UUID,
53
                                        new OutboxPollingTaskData(),
54
                                        Duration.ofSeconds(15),
1✔
55
                                        OUTBOX_POLLER_TASK_NAME
56
                                );
57

58
                                // Schedule the outbox cleanup task to run recurrently (e.g., every day)
59
                                schedulerService.scheduleRecurrently(
1✔
60
                                        OUTBOX_CLEANUP_TASK_UUID,
61
                                        new OutboxCleanupTaskData(),
62
                                        Duration.ofDays(1),
1✔
63
                                        OUTBOX_CLEANUP_TASK_NAME
64
                                );
65
                        } else {
NEW
66
                                schedulerService.deleteRecurringTask(OUTBOX_POLLER_TASK_UUID);
×
NEW
67
                                schedulerService.deleteRecurringTask(OUTBOX_CLEANUP_TASK_UUID);
×
68
                                
69
                        }
70
                } finally {
71
                        Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_SCHEDULER);
1✔
72
                }
73
        }
1✔
74
}
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