use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.
the class JobletUpdateHandler method copyJobletRequestsToQueues.
@Handler
private Mav copyJobletRequestsToQueues(@Param(PARAM_jobletType) OptionalString jobletType) {
List<JobletType<?>> jobletTypes = jobletType.isPresent() ? List.of(jobletTypeFactory.fromPersistentString(jobletType.get())) : jobletTypeFactory.getAllTypes();
long numCopied = 0;
for (JobletType<?> type : jobletTypes) {
Scanner<JobletRequest> requestsOfType = jobletRequestDao.scanType(type, false).include(jobletRequest -> JobletStatus.CREATED == jobletRequest.getStatus());
for (List<JobletRequest> requestBatch : requestsOfType.batch(100).iterable()) {
Map<JobletRequestQueueKey, List<JobletRequest>> requestsByQueueKey = Scanner.of(requestBatch).groupBy(jobletRequestQueueManager::getQueueKey);
for (JobletRequestQueueKey queueKey : requestsByQueueKey.keySet()) {
List<JobletRequest> jobletsForQueue = requestsByQueueKey.get(queueKey);
jobletQueueDao.getQueue(queueKey).putMulti(jobletsForQueue);
numCopied += jobletsForQueue.size();
}
logger.warn("copied {}", numCopied);
}
}
var dto = new DatarouterChangelogDtoBuilder("Joblet", jobletType.orElse("all"), "requeue", getSessionInfo().getRequiredSession().getUsername()).build();
changelogRecorder.record(dto);
return pageFactory.message(request, "copied " + numCopied);
}
use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.
the class JobletUpdateHandler method timeoutStuckRunning.
// is this used?
@Handler
private Mav timeoutStuckRunning(String type) {
JobletType<?> jobletType = jobletTypeFactory.fromPersistentString(type);
Scanner<JobletRequest> requests = jobletRequestDao.scanType(jobletType, false).include(request -> request.getStatus() == JobletStatus.RUNNING).include(request -> request.getReservedAgoMs().isPresent()).include(request -> request.getReservedAgoMs().get() > Duration.ofDays(2).toMillis());
long numTimedOut = 0;
for (List<JobletRequest> requestBatch : requests.batch(100).iterable()) {
List<JobletRequest> toSave = new ArrayList<>();
for (JobletRequest request : requestBatch) {
request.setStatus(JobletStatus.CREATED);
request.setNumFailures(0);
++numTimedOut;
}
jobletRequestDao.putMulti(toSave);
logger.warn("copied {}", numTimedOut);
}
changelogRecorder.record(new DatarouterChangelogDtoBuilder("Joblet", type, "timeoutStuckRunning", getSessionInfo().getRequiredSession().getUsername()).build());
return pageFactory.message(request, "timedOut " + numTimedOut);
}
use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.
the class JobletUpdateHandler method deleteGroup.
@Handler
private Mav deleteGroup(@Param(PARAM_jobletType) String typeString, @Param(PARAM_executionOrder) Integer executionOrder, @Param(PARAM_status) String status) {
JobletType<?> jobletType = jobletTypeFactory.fromPersistentString(typeString);
Objects.requireNonNull(jobletType, "No joblet type found with name=" + typeString);
JobletStatus statusString = JobletStatus.fromPersistentStringStatic(status);
JobletRequestKey prefix = JobletRequestKey.create(jobletType, executionOrder, null, null);
jobletRequestDao.scanWithPrefix(prefix).include(jobletRequest -> statusString == jobletRequest.getStatus()).map(Databean::getKey).batch(100).forEach(jobletRequestDao::deleteMulti);
String message = String.format("Deleted joblets with type %s, status %s, executionOrder %s", typeString, status, executionOrder);
var dto = new DatarouterChangelogDtoBuilder("Joblet", typeString + " " + status + " " + executionOrder, "deleteGroup", getSessionInfo().getRequiredSession().getUsername()).build();
changelogRecorder.record(dto);
return pageFactory.message(request, message);
}
use of io.datarouter.joblet.type.JobletType in project datarouter by hotpads.
the class JobletService method restartJoblets.
public long restartJoblets(JobletType<?> jobletType, JobletStatus jobletStatus) {
var numRestarted = new AtomicLong();
jobletRequestDao.scanType(jobletType, false).include(request -> request.getStatus() == jobletStatus).forEach(request -> {
request.setStatus(JobletStatus.CREATED);
request.setNumFailures(0);
jobletRequestDao.put(request);
if (Objects.equals(jobletSettings.queueMechanism.get(), JobletQueueMechanism.QUEUE.getPersistentString())) {
JobletRequestQueueKey queueKey = jobletRequestQueueManager.getQueueKey(request);
jobletQueueDao.getQueue(queueKey).put(request);
}
numRestarted.incrementAndGet();
logger.warn("restarted {}", numRestarted.get());
});
return numRestarted.get();
}
Aggregations