Skip to content

Commit

Permalink
#305, codacy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhu committed Oct 1, 2021
1 parent 917d222 commit 6525c51
Showing 1 changed file with 42 additions and 37 deletions.
79 changes: 42 additions & 37 deletions api-server/src/main/java/vermillion/http/HttpServerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1531,43 +1531,7 @@ public void downloadByQuery(RoutingContext context) {
return Completable.error(new FileNotFoundThrowable("The requested files are not found"));
}

SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();
scheduler.start();

logger.debug("Is scheduler started: " + scheduler.isStarted());
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("token", token);
jobDataMap.put("uuid", uuid);
jobDataMap.put("finalHits", hits);
jobDataMap.put("email", emailDetails.get("email"));

// define the job and tie it to our JobScheduler class
JobDetail job = JobBuilder.newJob(JobScheduler.class)
.withIdentity(String.valueOf(uuid), "download")
.usingJobData(jobDataMap)
.build();
logger.debug("Job key: " + job.getKey());

// Trigger the job to run now
Trigger trigger = newTrigger()
.withIdentity(String.valueOf(uuid), "download")
.startNow()
.withSchedule(simpleSchedule())
.build();
logger.debug("trigger key: " + trigger.getKey());

scheduler.getListenerManager().addJobListener(
new JobSchedulerListener());

// Tell quartz to schedule the job using our trigger
try {
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
logger.debug("Scheduler exception caused due to: " + e.getMessage());
e.printStackTrace();
}

invokeScheduler(token, uuid, emailDetails, hits);
return Completable.complete();
}).subscribe(()-> response.setStatusCode(ACCEPTED)
.setStatusMessage("Please kindly wait as your download links are getting ready")
Expand All @@ -1576,6 +1540,47 @@ public void downloadByQuery(RoutingContext context) {

}

private Completable invokeScheduler(String token, UUID uuid, Map<String, String> emailDetails, JsonArray hits) throws SchedulerException {
SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();
scheduler.start();

logger.debug("Is scheduler started: " + scheduler.isStarted());
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("token", token);
jobDataMap.put("uuid", uuid);
jobDataMap.put("finalHits", hits);
jobDataMap.put("email", emailDetails.get("email"));

// define the job and tie it to our JobScheduler class
JobDetail job = JobBuilder.newJob(JobScheduler.class)
.withIdentity(String.valueOf(uuid), "download")
.usingJobData(jobDataMap)
.build();
logger.debug("Job key: " + job.getKey());

// Trigger the job to run now
Trigger trigger = newTrigger()
.withIdentity(String.valueOf(uuid), "download")
.startNow()
.withSchedule(simpleSchedule())
.build();
logger.debug("trigger key: " + trigger.getKey());

scheduler.getListenerManager().addJobListener(
new JobSchedulerListener());

// Tell quartz to schedule the job using our trigger
try {
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
logger.debug("Scheduler exception caused due to: " + e.getMessage());
e.printStackTrace();
return Completable.error(new SchedulerException("Scheduler exception caught"));
}
return Completable.complete();
}

// TODO: Handle server token
// TODO: Handle regexes
// Method that makes the HTTPS request to the auth server
Expand Down

0 comments on commit 6525c51

Please sign in to comment.