use of io.datarouter.joblet.storage.jobletrequest.JobletRequestKey in project datarouter by hotpads.
the class JobletQueuesHandler method queues.
@Handler
private Mav queues(@Param(P_jobletType) String jobletType, @Param(P_executionOrder) Integer executionOrder) {
JobletType<?> type = jobletTypeFactory.fromPersistentString(jobletType);
JobletRequestKey prefix = new JobletRequestKey(type.getPersistentString(), executionOrder, null, null);
Scanner<JobletRequest> requests = jobletRequestDao.scanWithPrefix(prefix);
Collection<JobletSummary> summaries = JobletSummary.summarizeByQueueStatus(requests).values();
return pageFactory.startBuilder(request).withTitle(TITLE).withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(makeContent(type, executionOrder, summaries)).buildMav();
}
use of io.datarouter.joblet.storage.jobletrequest.JobletRequestKey in project datarouter by hotpads.
the class JobletService method jobletRequestExistsWithTypeAndStatus.
public boolean jobletRequestExistsWithTypeAndStatus(JobletType<?> jobletType, JobletStatus jobletStatus) {
JobletRequestKey key = JobletRequestKey.create(jobletType, null, null, null);
var range = new Range<>(key, true, key, true);
return jobletRequestDao.scan(range, 50).anyMatch(jobletRequest -> jobletRequest.getStatus() == jobletStatus);
}
use of io.datarouter.joblet.storage.jobletrequest.JobletRequestKey in project datarouter by hotpads.
the class QueueJobletRequestSelector method getJobletRequestForProcessing.
@Override
public Optional<JobletRequest> getJobletRequestForProcessing(PhaseTimer timer, JobletType<?> type, String reservedBy) {
for (JobletPriority priority : JobletPriority.values()) {
JobletRequestQueueKey queueKey = new JobletRequestQueueKey(type, priority);
if (jobletRequestQueueManager.shouldSkipQueue(queueKey)) {
datarouterJobletCounters.incQueueSkip(queueKey.getQueueName());
continue;
}
// set timeout to 0 so we return immediately. processor threads can do the waiting
Config config = new Config().setTimeout(Duration.ofMillis(0)).setVisibilityTimeoutMs(datarouterJobletSettingRoot.jobletTimeout.get().toMillis());
logger.info("jobletType={} queue={}", type, jobletQueueDao.getQueue(queueKey));
QueueMessage<JobletRequestKey, JobletRequest> message = jobletQueueDao.getQueue(queueKey).peek(config);
timer.add("peek");
if (message == null) {
jobletRequestQueueManager.onJobletRequestQueueMiss(queueKey);
continue;
}
datarouterJobletCounters.incQueueHit(queueKey.getQueueName());
JobletRequest jobletRequest = message.getDatabean();
boolean existsInDb = jobletRequestDao.exists(jobletRequest.getKey());
timer.add("check exists");
if (!existsInDb) {
logger.warn("draining non-existent JobletRequest without processing jobletRequest={}", jobletRequest);
datarouterJobletCounters.ignoredRequestMissingFromDb(type);
jobletQueueDao.getQueue(queueKey).ack(message.getKey());
timer.add("ack missing request");
continue;
}
jobletRequest.setQueueMessageKey(message.getKey());
jobletRequest.setReservedBy(reservedBy);
jobletRequest.setReservedAt(System.currentTimeMillis());
jobletRequest.setStatus(JobletStatus.RUNNING);
jobletRequestDao.put(jobletRequest);
if (!jobletRequest.getRestartable()) {
// don't let SQS give this joblet out again
jobletQueueDao.getQueue(queueKey).ack(message.getKey());
timer.add("ack non-restartable");
}
return Optional.of(jobletRequest);
}
return Optional.empty();
}
use of io.datarouter.joblet.storage.jobletrequest.JobletRequestKey in project datarouter by hotpads.
the class JobletRequeueJob method requeue.
private void requeue(JobletRequest request) {
JobletRequestQueueKey queueKey = jobletRequestQueueManager.getQueueKey(request);
// capture the old "created" for later delete
JobletRequestKey oldKey = request.getKey().copy();
request.getKey().setCreated(System.currentTimeMillis());
jobletRequestDao.put(request);
jobletQueueDao.put(queueKey, request);
jobletRequestDao.delete(oldKey);
logger.warn("requeued one oldKey={} newKey={}", oldKey, request.getKey());
}
use of io.datarouter.joblet.storage.jobletrequest.JobletRequestKey in project datarouter by hotpads.
the class JobletRequeueJob method anyExistWithMediumAge.
private boolean anyExistWithMediumAge(JobletRequestKey prefix) {
JobletRequestKey start = prefix.copy().withCreated(Instant.now().minus(OLD_AGE).toEpochMilli());
JobletRequestKey end = prefix.copy().withCreated(Instant.now().minus(MIDDLE_AGE).toEpochMilli());
var range = new Range<>(start, end);
return jobletRequestDao.scan(range).include(request -> request.getStatus() == JobletStatus.CREATED).hasAny();
}
Aggregations