Search in sources :

Example 1 with JobletDataKey

use of io.datarouter.joblet.storage.jobletdata.JobletDataKey in project datarouter by hotpads.

the class JobletService method getJobletPackagesForJobletRequests.

private List<JobletPackage> getJobletPackagesForJobletRequests(Collection<JobletRequest> jobletRequests) {
    List<JobletDataKey> keys = Scanner.of(jobletRequests).map(JobletRequest::getJobletDataKey).list();
    Map<Long, JobletData> dataKeyToJobletData = jobletDataDao.getMulti(keys).stream().collect(Collectors.toMap(jobletData -> jobletData.getKey().getId(), Function.identity()));
    return jobletRequests.stream().map(jobletRequest -> {
        Long dataKey = jobletRequest.getJobletDataId();
        JobletData jobletData = dataKeyToJobletData.get(dataKey);
        return new JobletPackage(jobletRequest, jobletData);
    }).collect(Collectors.toList());
}
Also used : IntStream(java.util.stream.IntStream) Scanner(io.datarouter.scanner.Scanner) DatarouterJobletSettingRoot(io.datarouter.joblet.setting.DatarouterJobletSettingRoot) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) JobletPackage(io.datarouter.joblet.model.JobletPackage) JobletRequestSelector(io.datarouter.joblet.queue.JobletRequestSelector) ExceptionRecorder(io.datarouter.web.exception.ExceptionRecorder) LoggerFactory(org.slf4j.LoggerFactory) JobletRequestQueueManager(io.datarouter.joblet.queue.JobletRequestQueueManager) Singleton(javax.inject.Singleton) ServerName(io.datarouter.storage.config.properties.ServerName) Function(java.util.function.Function) JobletStatus(io.datarouter.joblet.enums.JobletStatus) Inject(javax.inject.Inject) JobletType(io.datarouter.joblet.type.JobletType) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) JobletRequestSelectorFactory(io.datarouter.joblet.queue.JobletRequestSelectorFactory) Map(java.util.Map) Config(io.datarouter.storage.config.Config) HashMethods(io.datarouter.util.HashMethods) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) JobletDataKey(io.datarouter.joblet.storage.jobletdata.JobletDataKey) PhaseTimer(io.datarouter.util.timer.PhaseTimer) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletExceptionCategory(io.datarouter.joblet.JobletExceptionCategory) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey) Logger(org.slf4j.Logger) DatarouterJobletCounters(io.datarouter.joblet.DatarouterJobletCounters) DatarouterJobletDataDao(io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao) Collection(java.util.Collection) DatarouterJobletQueueDao(io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Range(io.datarouter.util.tuple.Range) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Databean(io.datarouter.model.databean.Databean) CachedWebappInstancesOfThisServerType(io.datarouter.webappinstance.service.CachedWebappInstancesOfThisServerType) Entry(java.util.Map.Entry) Optional(java.util.Optional) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData) PutMethod(io.datarouter.storage.config.PutMethod) JobletQueueMechanism(io.datarouter.joblet.enums.JobletQueueMechanism) JobletDataKey(io.datarouter.joblet.storage.jobletdata.JobletDataKey) AtomicLong(java.util.concurrent.atomic.AtomicLong) JobletPackage(io.datarouter.joblet.model.JobletPackage) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData)

Example 2 with JobletDataKey

use of io.datarouter.joblet.storage.jobletdata.JobletDataKey in project datarouter by hotpads.

the class JobletVacuumJob method run.

@Override
public void run(TaskTracker tracker) {
    Iterable<JobletRequest> jobletRequests = jobletRequestDao.scan().iterable();
    List<JobletRequestKey> jobletsToDelete = new ArrayList<>();
    List<JobletDataKey> jobletDataToDelete = new ArrayList<>();
    for (JobletRequest jobletRequest : jobletRequests) {
        if (shouldDelete(jobletRequest)) {
            jobletsToDelete.add(jobletRequest.getKey());
            jobletDataToDelete.add(jobletRequest.getJobletDataKey());
            jobletRequestsDeleted++;
            itemsDeleted = itemsDeleted + jobletRequest.getNumItems();
            if (jobletsToDelete.size() >= BATCH_SIZE) {
                deleteJobletRequests(jobletsToDelete, jobletDataToDelete);
            }
        }
    }
    if (!jobletsToDelete.isEmpty()) {
        deleteJobletRequests(jobletsToDelete, jobletDataToDelete);
    }
}
Also used : JobletDataKey(io.datarouter.joblet.storage.jobletdata.JobletDataKey) JobletRequestKey(io.datarouter.joblet.storage.jobletrequest.JobletRequestKey) ArrayList(java.util.ArrayList) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Aggregations

JobletDataKey (io.datarouter.joblet.storage.jobletdata.JobletDataKey)2 JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)2 JobletRequestKey (io.datarouter.joblet.storage.jobletrequest.JobletRequestKey)2 DatarouterJobletCounters (io.datarouter.joblet.DatarouterJobletCounters)1 JobletExceptionCategory (io.datarouter.joblet.JobletExceptionCategory)1 JobletQueueMechanism (io.datarouter.joblet.enums.JobletQueueMechanism)1 JobletStatus (io.datarouter.joblet.enums.JobletStatus)1 JobletPackage (io.datarouter.joblet.model.JobletPackage)1 JobletRequestQueueManager (io.datarouter.joblet.queue.JobletRequestQueueManager)1 JobletRequestSelector (io.datarouter.joblet.queue.JobletRequestSelector)1 JobletRequestSelectorFactory (io.datarouter.joblet.queue.JobletRequestSelectorFactory)1 DatarouterJobletSettingRoot (io.datarouter.joblet.setting.DatarouterJobletSettingRoot)1 DatarouterJobletDataDao (io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao)1 JobletData (io.datarouter.joblet.storage.jobletdata.JobletData)1 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)1 DatarouterJobletQueueDao (io.datarouter.joblet.storage.jobletrequestqueue.DatarouterJobletQueueDao)1 JobletRequestQueueKey (io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)1 JobletType (io.datarouter.joblet.type.JobletType)1 JobletTypeFactory (io.datarouter.joblet.type.JobletTypeFactory)1 Databean (io.datarouter.model.databean.Databean)1