Search in sources :

Example 1 with JobletRequest

use of io.datarouter.joblet.storage.jobletrequest.JobletRequest in project datarouter by hotpads.

the class TableSamplerTestTool method executeJobletsAndCollectSamples.

public static List<TableSample> executeJobletsAndCollectSamples(DatarouterInjector injector, List<JobletPackage> jobletPackages) {
    List<TableSample> results = new ArrayList<>();
    for (JobletData jobletData : JobletPackage.getJobletDatas(jobletPackages)) {
        TableSpanSamplerJoblet joblet = injector.getInstance(TableSpanSamplerJoblet.class);
        JobletRequest jobletRequest = new JobletRequest();
        // this field referenced by the joblet
        jobletRequest.getKey().setCreated(System.currentTimeMillis());
        joblet.setJobletRequest(jobletRequest);
        TableSpanSamplerJobletParams params = new TableSpanSamplerJobletCodec().unmarshallData(jobletData.getData());
        joblet.setJobletParams(params);
        joblet.process();
        results.addAll(joblet.getSamples());
    }
    return results;
}
Also used : TableSpanSamplerJobletCodec(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet.TableSpanSamplerJobletCodec) ArrayList(java.util.ArrayList) TableSpanSamplerJoblet(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet) TableSample(io.datarouter.nodewatch.storage.tablesample.TableSample) TableSpanSamplerJobletParams(io.datarouter.nodewatch.joblet.TableSpanSamplerJoblet.TableSpanSamplerJobletParams) JobletData(io.datarouter.joblet.storage.jobletdata.JobletData) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Example 2 with JobletRequest

use of io.datarouter.joblet.storage.jobletrequest.JobletRequest in project datarouter by hotpads.

the class MysqlLockForUpdateJobletRequestSelector method getJobletRequestForProcessing.

@Override
public Optional<JobletRequest> getJobletRequestForProcessing(PhaseTimer timer, JobletType<?> type, String reservedBy) {
    while (true) {
        var mysqlOp = new GetJobletRequest(reservedBy, type, datarouter, jobletRequestDao, mysqlFieldCodecFactory, mysqlSqlFactory, jobletRequestSqlBuilder, jobletService);
        JobletRequest jobletRequest = sessionExecutor.runWithoutRetries(mysqlOp);
        timer.add("GetJobletRequest");
        if (jobletRequest == null) {
            // for back-off
            jobletRequestQueueManager.onJobletRequestMissForAllPriorities(type);
            return Optional.empty();
        }
        if (!jobletRequest.getStatus().isRunning()) {
            // weird flow. it was probably just marked as timedOut, so skip it
            continue;
        }
        var queueKey = new JobletRequestQueueKey(type, jobletRequest.getKey().getPriority());
        datarouterJobletCounters.incQueueHit(queueKey.getQueueName());
        return Optional.of(jobletRequest);
    }
}
Also used : GetJobletRequest(io.datarouter.jobletmysql.txn.GetJobletRequest) GetJobletRequest(io.datarouter.jobletmysql.txn.GetJobletRequest) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)

Example 3 with JobletRequest

use of io.datarouter.joblet.storage.jobletrequest.JobletRequest in project datarouter by hotpads.

the class MysqlUpdateAndScanJobletRequestSelector method getJobletRequestForProcessing.

@Override
public Optional<JobletRequest> getJobletRequestForProcessing(PhaseTimer timer, JobletType<?> type, String reservedBy) {
    ReserveJobletRequest mysqlOp = new ReserveJobletRequest(reservedBy, type, datarouter, jobletRequestDao, mysqlSqlFactory, jobletRequestSqlBuilder);
    while (sessionExecutor.runWithoutRetries(mysqlOp)) {
        // returns false if no joblet found
        JobletRequest jobletRequest = jobletRequestDao.getReservedRequest(type, reservedBy, Isolation.readUncommitted);
        if (JobletStatus.CREATED == jobletRequest.getStatus()) {
            jobletRequest.setReservedBy(reservedBy);
            jobletRequest.setReservedAt(System.currentTimeMillis());
            jobletRequest.setStatus(JobletStatus.RUNNING);
            jobletRequestDao.put(jobletRequest);
            return Optional.of(jobletRequest);
        }
        // we got a previously timed-out joblet
        jobletRequest.incrementNumTimeouts();
        if (jobletRequest.getNumTimeouts() <= JobletService.MAX_JOBLET_RETRIES) {
            jobletRequestDao.put(jobletRequest);
            JobletRequestQueueKey queueKey = new JobletRequestQueueKey(type, jobletRequest.getKey().getPriority());
            datarouterJobletCounters.incQueueHit(queueKey.getQueueName());
            return Optional.of(jobletRequest);
        }
        jobletRequest.setStatus(JobletStatus.TIMED_OUT);
        jobletRequestDao.put(jobletRequest);
    // loop around for another
    }
    // for back-off
    jobletRequestQueueManager.onJobletRequestMissForAllPriorities(type);
    return Optional.empty();
}
Also used : ReserveJobletRequest(io.datarouter.jobletmysql.txn.ReserveJobletRequest) ReserveJobletRequest(io.datarouter.jobletmysql.txn.ReserveJobletRequest) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletRequestQueueKey(io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)

Example 4 with JobletRequest

use of io.datarouter.joblet.storage.jobletrequest.JobletRequest in project datarouter by hotpads.

the class GetJobletRequest method runOnce.

@Override
public JobletRequest runOnce() {
    PreparedStatement selectStatement = makeSelectStatement().prepare(getConnection());
    JobletRequest jobletRequest = MysqlTool.selectDatabeans(mysqlFieldCodecFactory, fieldInfo.getDatabeanSupplier(), fieldInfo.getFields(), selectStatement).stream().findFirst().orElse(null);
    if (jobletRequest == null) {
        return null;
    }
    jobletService.updateStatusToRunning(jobletRequest, reservedBy);
    return jobletRequest;
}
Also used : PreparedStatement(java.sql.PreparedStatement) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Example 5 with JobletRequest

use of io.datarouter.joblet.storage.jobletrequest.JobletRequest in project datarouter by hotpads.

the class JobletExceptionHandler method makeContent.

private ContainerTag<?> makeContent(List<JobletRequest> rows) {
    var title = h4(TITLE).withClass("mt-2");
    var table = new J2HtmlTable<JobletRequest>().withClasses("sortable table table-sm table-striped border").withHtmlColumn("Exception ID", row -> {
        String id = row.getExceptionRecordId();
        return externalLinkBuilder.get().exception(request.getContextPath(), id).map(href -> td(a(id).withHref(href))).orElse(td(id));
    }).withColumn("Type", row -> row.getKey().getType()).withColumn("Execution order", row -> row.getKey().getExecutionOrder()).withColumn("Batch sequence", row -> row.getKey().getBatchSequence()).withColumn("Data ID", JobletRequest::getJobletDataId).withColumn("Reserved by", JobletRequest::getReservedBy).withColumn("Created ago", JobletRequest::getCreatedAgo).withColumn("Restartable", JobletRequest::getRestartable).withColumn("Num items", JobletRequest::getNumItems).withColumn("Queue ID", JobletRequest::getQueueId).build(rows);
    return div(title, table).withClass("container-fluid");
}
Also used : J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) JobletPageFactory(io.datarouter.joblet.JobletPageFactory) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.h4(j2html.TagCreator.h4) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) TagCreator.a(j2html.TagCreator.a) JobletStatus(io.datarouter.joblet.enums.JobletStatus) ContainerTag(j2html.tags.ContainerTag) Inject(javax.inject.Inject) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) JobletExternalLinkBuilderSupplier(io.datarouter.joblet.nav.JobletExternalLinkBuilder.JobletExternalLinkBuilderSupplier) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) Param(io.datarouter.web.handler.types.Param) TagCreator.div(j2html.TagCreator.div) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Aggregations

JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)20 JobletRequestQueueKey (io.datarouter.joblet.storage.jobletrequestqueue.JobletRequestQueueKey)8 JobletRequestKey (io.datarouter.joblet.storage.jobletrequest.JobletRequestKey)7 JobletStatus (io.datarouter.joblet.enums.JobletStatus)6 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)6 BaseHandler (io.datarouter.web.handler.BaseHandler)6 List (java.util.List)6 Inject (javax.inject.Inject)6 JobletTypeFactory (io.datarouter.joblet.type.JobletTypeFactory)5 Scanner (io.datarouter.scanner.Scanner)5 ArrayList (java.util.ArrayList)5 JobletPageFactory (io.datarouter.joblet.JobletPageFactory)4 JobletRequestQueueManager (io.datarouter.joblet.queue.JobletRequestQueueManager)4 JobletData (io.datarouter.joblet.storage.jobletdata.JobletData)4 JobletType (io.datarouter.joblet.type.JobletType)4 Databean (io.datarouter.model.databean.Databean)4 Mav (io.datarouter.web.handler.mav.Mav)4 Param (io.datarouter.web.handler.types.Param)4 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)4 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)3