use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class TrackerRuleEngineMessageManager method consume.
@JmsListener(destination = Topics.TRACKER_IMPORT_RULE_ENGINE_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, IOException {
TrackerSideEffectDataBundle bundle = toBundle(message);
if (bundle == null) {
return;
}
JobConfiguration jobConfiguration = new JobConfiguration("", JobType.TRACKER_IMPORT_RULE_ENGINE_JOB, bundle.getAccessedBy(), true);
bundle.setJobConfiguration(jobConfiguration);
TrackerRuleEngineThread notificationThread = trackerRuleEngineThreadObjectFactory.getObject();
notificationThread.setSideEffectDataBundle(bundle);
executeJob(notificationThread);
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class NotificationMap method add.
public void add(JobConfiguration configuration, Notification notification) {
String jobId = configuration.getUid();
if (jobId == null) {
return;
}
JobType jobType = configuration.getJobType();
Deque<String> notifications = notificationsJobIdOrder.get(jobType);
if (notifications.size() > MAX_POOL_TYPE_SIZE) {
notificationsWithType.get(jobType).remove(notifications.removeLast());
}
notifications.addFirst(jobId);
notificationsWithType.get(jobType).computeIfAbsent(jobId, key -> new ConcurrentLinkedDeque<>()).addFirst(notification);
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class RedisLeaderManager method electLeader.
@Override
public void electLeader() {
log.debug("Election attempt by nodeId:" + this.nodeUuid);
redisTemplate.opsForValue().setIfAbsent(KEY, nodeUuid, timeToLiveSeconds, TimeUnit.SECONDS);
redisTemplate.opsForValue().setIfAbsent(NODE_ID_KEY, nodeId, timeToLiveSeconds, TimeUnit.SECONDS);
if (isLeader()) {
renewLeader();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, (int) (this.timeToLiveSeconds / 2));
log.debug("Next leader renewal job nodeId:%s set at %s", this.nodeUuid, calendar.getTime().toString());
JobConfiguration leaderRenewalJobConfiguration = new JobConfiguration(CLUSTER_LEADER_RENEWAL, JobType.LEADER_RENEWAL, null, true);
leaderRenewalJobConfiguration.setLeaderOnlyJob(true);
schedulingManager.scheduleWithStartTime(leaderRenewalJobConfiguration, calendar.getTime());
}
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class NotifierTest method testInsertingNotificationsInSameJobConcurrently.
@Test
void testInsertingNotificationsInSameJobConcurrently() throws InterruptedException {
ExecutorService e = Executors.newFixedThreadPool(5);
JobConfiguration jobConfig = createJobConfig(-1);
notifier.notify(jobConfig, "somethingid");
IntStream.range(0, 100).forEach(i -> e.execute(() -> notifier.notify(jobConfig, "somethingid" + i)));
IntStream.range(0, 100).forEach(i -> {
for (Notification notification : notifier.getNotificationsByJobType(METADATA_IMPORT).get(jobConfig.getUid())) {
// Iterate over notifications when new notification are added
assertNotNull(notification.getUid());
}
});
awaitTermination(e);
assertEquals(101, notifier.getNotificationsByJobType(METADATA_IMPORT).get(jobConfig.getUid()).size());
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class NotifierTest method createJobConfig.
private JobConfiguration createJobConfig(int i) {
JobConfiguration jobConfig = new JobConfiguration(null, METADATA_IMPORT, user.getUid(), false);
jobConfig.setUid("jobId" + i);
return jobConfig;
}
Aggregations