use of org.activityinfo.model.job.JobDescriptor in project activityinfo by bedatadriven.
the class JobTaskServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (Strings.isNullOrEmpty(req.getHeader("X-AppEngine-QueueName"))) {
LOGGER.severe("Unauthorized task request");
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
String jobKey = req.getParameter(JobResource.JOB_KEY_PARAM);
final JobEntity jobEntity = JobStore.getUserJob(jobKey).now();
if (jobEntity == null) {
LOGGER.severe("Job " + jobKey + " not found");
resp.setStatus(200);
return;
}
if (jobEntity.getState() != JobState.STARTED) {
LOGGER.info("Job " + jobKey + " has state " + jobEntity.getState() + ", stopping here.");
resp.setStatus(200);
return;
}
User user = entityManager.get().find(User.class, (int) jobEntity.getUserId());
authProvider.set(user.asAuthenticatedUser());
Locale jobLocale = jobLocale(user, jobEntity);
ThreadLocalLocaleProvider.pushLocale(jobLocale);
LOGGER.info("Set authenticated user to " + user.getEmail() + " [" + jobLocale + "]");
JobExecutor executor = executorFactory.create(jobEntity.getType());
JobDescriptor descriptor = jobEntity.parseDescriptor();
try {
final JobResult result = executor.execute(descriptor);
markCompleted(jobEntity, result);
} catch (Exception e) {
markFailed(jobEntity, e);
}
}
Aggregations