package sb.tasks.pages;

import com.jcabi.log.Logger;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import ratpack.exec.Promise;
import ratpack.handling.Context;
import ratpack.jackson.Jackson;
import sb.tasks.system.SchedulerInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class JobPerform implements HttpPage {

    private final Scheduler scheduler;

    public JobPerform(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    @Override
    public void handle(Context ctx) {
        Promise<Ids> promise = ctx.parse(Ids.class);
        promise.then(f -> {
            List<String> jobkeys = f.getAll();
            SchedulerInfo schInfo = new SchedulerInfo(scheduler);
            Map<String, HttpAnswer> answers = new HashMap<>();
            for (String jobkey : jobkeys) {
                JobKey key = schInfo.get(jobkey);
                scheduler.triggerJob(key);
                Logger.info(this, "Job with key = %s triggered", key);
                answers.put(jobkey, new SuccessAns());
            }
            ctx.render(Jackson.json(answers));
        });
    }
}

@@ -837,24 +837,50 @@
  jobkeys) %7B%0A
+                try %7B%0A    
             
@@ -933,16 +933,20 @@
         
+    
 schedule
@@ -980,16 +980,20 @@
         
+  
+  
 Logger.i
@@ -996,16 +996,27 @@
 er.info(
+JobPerform.
 this, %22J
@@ -1066,16 +1066,20 @@
         
+    
 answers.
@@ -1105,24 +1105,142 @@
 cessAns());%0A
+                %7D catch (Exception ex) %7B%0A                    answers.put(jobkey, new FailureAns());%0A                %7D%0A
             

fail answers