Search in sources :

Example 1 with JobletRequestKey

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();
}
Also used : JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) JobletSummary(io.datarouter.joblet.dto.JobletSummary) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with JobletRequestKey

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);
}
Also used : JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Range(io.datarouter.util.tuple.Range)

Example 3 with JobletRequestKey

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();
}
Also used : JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) JobletPriority(io.datarouter.joblet.enums.JobletPriority) Config(io.datarouter.storage.config.Config) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Example 4 with JobletRequestKey

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());
}
Also used : JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)

Example 5 with JobletRequestKey

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();
}
Also used : JobletPriority(io.datarouter.joblet.enums.JobletPriority) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) Logger(org.slf4j.Logger) BaseJob(io.datarouter.job.BaseJob) LoggerFactory(org.slf4j.LoggerFactory) JobletRequestQueueManager(io.datarouter.joblet.queue.JobletRequestQueueManager) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) DatarouterJobletQueueDao(io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao) Instant(java.time.Instant) JobletStatus(io.datarouter.joblet.enums.JobletStatus) Inject(javax.inject.Inject) Range(io.datarouter.util.tuple.Range) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Duration(java.time.Duration) ActiveJobletTypeFactory(io.datarouter.joblet.type.ActiveJobletTypeFactory) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) EnumSet(java.util.EnumSet) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) Range(io.datarouter.util.tuple.Range)

Aggregations

JobletRequestKey (io.datarouter.joblet.storage.jobletrequest.JobletRequestKey)7 JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)5 JobletRequestQueueKey (io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)4 JobletPriority (io.datarouter.joblet.enums.JobletPriority)2 JobletStatus (io.datarouter.joblet.enums.JobletStatus)2 JobletRequestQueueManager (io.datarouter.joblet.queue.JobletRequestQueueManager)2 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)2 DatarouterJobletQueueDao (io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao)2 Range (io.datarouter.util.tuple.Range)2 BaseHandler (io.datarouter.web.handler.BaseHandler)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ChangelogRecorder (io.datarouter.instrumentation.changelog.ChangelogRecorder)1 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)1 TaskTracker (io.datarouter.instrumentation.task.TaskTracker)1 BaseJob (io.datarouter.job.BaseJob)1 JobletPageFactory (io.datarouter.joblet.JobletPageFactory)1