Search in sources :

Example 6 with JobletPackage

use of io.datarouter.joblet.model.JobletPackage in project datarouter by hotpads.

the class SleepingJobletHandler method createSleepingJoblets.

@Handler(defaultHandler = true)
private Mav createSleepingJoblets(@Param(P_numJoblets) OptionalInteger numJoblets, @Param(P_sleepMs) OptionalLong sleepMs, @Param(P_executionOrder) OptionalInteger executionOrder, @Param(P_includeFailures) OptionalBoolean includeFailures, @Param(P_failEveryN) OptionalInteger failEveryN, @Param(P_submitAction) OptionalString submitAction) {
    var form = new HtmlForm().withMethod("post");
    form.addTextField().withDisplay("Number of Joblets").withName(P_numJoblets).withPlaceholder("1000").withValue(numJoblets.map(Object::toString).orElse(1000 + ""));
    form.addTextField().withDisplay("Sleep Millis").withName(P_sleepMs).withPlaceholder("1000").withValue(sleepMs.map(Object::toString).orElse(1000 + ""));
    form.addTextField().withDisplay("Execution Order").withName(P_executionOrder).withPlaceholder(JobletPriority.DEFAULT.getExecutionOrder() + "").withValue(executionOrder.map(Object::toString).orElse(JobletPriority.DEFAULT.getExecutionOrder() + ""));
    form.addCheckboxField().withDisplay("Include Failures").withName(P_includeFailures).withChecked(includeFailures.orElse(true));
    form.addTextField().withDisplay("Fail Every N").withName(P_failEveryN).withPlaceholder(100 + "").withValue(failEveryN.map(Object::toString).orElse(100 + ""));
    form.addButton().withDisplay("Create Joblets").withValue("anything");
    if (submitAction.isEmpty() || form.hasErrors()) {
        return pageFactory.startBuilder(request).withTitle(TITLE).withContent(makeContent(form)).buildMav();
    }
    JobletPriority priority = JobletPriority.fromExecutionOrder(executionOrder.get());
    List<JobletPackage> jobletPackages = new ArrayList<>();
    for (int i = 0; i < numJoblets.get(); ++i) {
        int numFailuresForThisJoblet = 0;
        if (includeFailures.orElse(false)) {
            boolean failThisJoblet = i % failEveryN.orElse(10) == 0;
            if (failThisJoblet) {
                // +3 to see if it causes a problem
                numFailuresForThisJoblet = JobletRequest.MAX_FAILURES + 3;
            }
        }
        SleepingJobletParams params = new SleepingJobletParams(String.valueOf(i), sleepMs.get(), numFailuresForThisJoblet);
        // specify this so joblets execute in precise order
        int batchSequence = i;
        JobletPackage jobletPackage = JobletPackage.createDetailed(SleepingJoblet.JOBLET_TYPE, priority, Instant.now(), batchSequence, true, null, null, params);
        jobletPackages.add(jobletPackage);
    }
    jobletService.submitJobletPackages(jobletPackages);
    return pageFactory.message(request, String.format("created %s @%s ms each", numJoblets.get(), sleepMs.get()));
}
Also used : HtmlForm(io.datarouter.web.html.form.HtmlForm) JobletPriority(io.datarouter.joblet.enums.JobletPriority) SleepingJobletParams(io.datarouter.joblet.test.SleepingJoblet.SleepingJobletParams) ArrayList(java.util.ArrayList) JobletPackage(io.datarouter.joblet.model.JobletPackage) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

JobletPackage (io.datarouter.joblet.model.JobletPackage)6 JobletPriority (io.datarouter.joblet.enums.JobletPriority)3 Databean (io.datarouter.model.databean.Databean)3 Scanner (io.datarouter.scanner.Scanner)3 BaseHandler (io.datarouter.web.handler.BaseHandler)3 HtmlForm (io.datarouter.web.html.form.HtmlForm)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Inject (javax.inject.Inject)3 JobletService (io.datarouter.joblet.service.JobletService)2 JobletRequest (io.datarouter.joblet.storage.jobletrequest.JobletRequest)2 PrimaryKey (io.datarouter.model.key.primary.PrimaryKey)2 TableSamplerService (io.datarouter.nodewatch.service.TableSamplerService)2 TableSample (io.datarouter.nodewatch.storage.tablesample.TableSample)2 TableSampleKey (io.datarouter.nodewatch.storage.tablesample.TableSampleKey)2 TableSamplerTool (io.datarouter.nodewatch.util.TableSamplerTool)2 Config (io.datarouter.storage.config.Config)2 DatarouterNodes (io.datarouter.storage.node.DatarouterNodes)2 PhysicalSortedStorageNode (io.datarouter.storage.node.op.raw.SortedStorage.PhysicalSortedStorageNode)2 PrimaryKeyPercentCodecTool (io.datarouter.storage.util.PrimaryKeyPercentCodecTool)2