Search in sources :

Example 1 with SleepingJobletParams

use of io.datarouter.joblet.test.SleepingJoblet.SleepingJobletParams 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

JobletPriority (io.datarouter.joblet.enums.JobletPriority)1 JobletPackage (io.datarouter.joblet.model.JobletPackage)1 SleepingJobletParams (io.datarouter.joblet.test.SleepingJoblet.SleepingJobletParams)1 BaseHandler (io.datarouter.web.handler.BaseHandler)1 HtmlForm (io.datarouter.web.html.form.HtmlForm)1 ArrayList (java.util.ArrayList)1