use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.
the class TableCountJob method run.
@Override
public void run(TaskTracker tracker) {
tableSamplerService.scanCountableNodes().advanceUntil($ -> tracker.shouldStop()).each($ -> tracker.increment()).map(ClientTableEntityPrefixNameWrapper::new).each(item -> tracker.setLastItemProcessed(item.toString())).map(nodeNames -> tableSamplerService.getCurrentTableCountFromSamples(nodeNames.getClientName(), nodeNames.getTableName())).forEach(tableCount -> {
tableCountDao.put(tableCount);
latestTableCountDao.put(new LatestTableCount(tableCount));
});
}
use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.
the class JobRunner method runInTest.
private void runInTest(BaseJob job) {
Class<? extends BaseJob> jobClass = job.getClass();
TaskTracker tracker = new MemoryTaskTracker(jobClass);
try {
job.run(tracker);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.
the class JobletDataVacuumJob method run.
@Override
public void run(TaskTracker tracker) throws RuntimeException {
AtomicLong earliestCreated = new AtomicLong(Instant.now().toEpochMilli());
jobletRequestDao.scan().advanceUntil($ -> tracker.shouldStop()).each($ -> tracker.increment()).forEach(jobletRequest -> {
if (jobletRequest.getKey().getCreated() <= earliestCreated.longValue()) {
earliestCreated.set(jobletRequest.getKey().getCreated());
}
});
AtomicInteger jobletDeletionCount = new AtomicInteger(0);
jobletDataDao.scan().advanceUntil($ -> tracker.shouldStop()).batch(1_000).each(batch -> tracker.increment(batch.size())).map(batch -> {
return batch.stream().filter(data -> data.getCreated() == null || data.getCreated() < earliestCreated.longValue()).map(Databean::getKey).collect(Collectors.toList());
}).each(jobletDataDao::deleteMulti).map(List::size).each(jobletDeletionCount::getAndAdd).forEach($ -> logger.warn("JobletDataVacuumJob deleted {} JobletDatas", NumberFormatter.addCommas(jobletDeletionCount)));
logger.warn("Completed JobletDataVacuumJob deleted {} total JobletDatas", NumberFormatter.addCommas(jobletDeletionCount));
}
use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.
the class OpPerformanceRecordAggregationJob method run.
@Override
public void run(TaskTracker tracker) {
String currentOpName = null;
List<OpPerformanceRecordKey> recordsToDelete = new ArrayList<>(BATCH_SIZE);
Map<Integer, AggregatedRecord> aggregatedRecordsByBatchSize = new HashMap<>();
for (OpPerformanceRecord record : opPerformanceRecordDao.scan().iterable()) {
if (currentOpName != null && !currentOpName.equals(record.getKey().getOpName())) {
saveAggregatedRecord(aggregatedRecordsByBatchSize);
aggregatedRecordsByBatchSize.clear();
}
currentOpName = record.getKey().getOpName();
aggregatedRecordsByBatchSize.computeIfAbsent(record.getBatchSize(), $ -> new AggregatedRecord(record.getKey().getOpName(), record.getBatchSize())).addRecord(record);
recordsToDelete.add(record.getKey());
if (recordsToDelete.size() > BATCH_SIZE) {
opPerformanceRecordDao.deleteMulti(new ArrayList<>(recordsToDelete));
recordsToDelete.clear();
}
}
saveAggregatedRecord(aggregatedRecordsByBatchSize);
opPerformanceRecordDao.deleteMulti(recordsToDelete);
}
use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.
the class ExampleTaskTrackerHandler method countFiles.
@Handler
public Mav countFiles(String parentPath, OptionalLong logEveryN) throws IOException {
// create a TaskTracker
TaskTracker tracker = trackerFactory.create(// determines the tracker name
ExampleTaskTrackerHandler.class.getSimpleName(), // triggered by web request
LongRunningTaskType.REQUEST, // deadline
Instant.now().plus(Duration.ofMinutes(1)), // gracefully stop when the deadline is reached
true, // record which user triggered the request, viewable in the UI
getSessionInfo().getNonEmptyUsernameOrElse("anonymous"));
// update and check the TaskTracker during a potentially long task
Scanner.of(Files.walk(Paths.get(parentPath))).advanceUntil($ -> tracker.shouldStop()).map(Object::toString).each($ -> tracker.increment()).each(tracker::setLastItemProcessed).sample(logEveryN.orElse(1L), true).forEach(item -> logger.warn("{}={}", tracker.getCount(), item));
// return a message to the user, obtaining the count from the tracker
return new MessageMav("counted " + tracker.getCount());
}
Aggregations