use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.
the class ScheduledJob method executeInternal.
@Override
public void executeInternal(JobExecutionContext context) throws JobExecutionException {
Integer taskId = (Integer) context.getJobDetail().getJobDataMap().get(ScheduledTask.ID);
SysTask task = BeanComponent.getSysTaskService().getEntity(taskId);
if (null != task) {
if (ScheduledTask.TASK_STATUS_READY == task.getStatus() && BeanComponent.getSysTaskService().updateStatusToRunning(task.getId())) {
LogTask entity = new LogTask(task.getSiteId(), task.getId(), new Date(), false);
BeanComponent.getLogTaskService().save(entity);
boolean success = false;
String result;
try {
success = true;
Map<String, Object> map = new HashMap<>();
map.put("task", task);
SysSite site = BeanComponent.getSiteService().getEntity(task.getSiteId());
AbstractFreemarkerView.exposeSite(map, site);
String fulllPath = SiteComponent.getFullFileName(site, task.getFilePath());
result = FreeMarkerUtils.generateStringByFile(fulllPath, BeanComponent.getTemplateComponent().getTaskConfiguration(), map);
} catch (IOException | TemplateException e) {
result = e.getMessage();
}
entity.setEndtime(new Date());
entity.setSuccess(success);
entity.setResult(result);
BeanComponent.getLogTaskService().update(entity.getId(), entity, ignoreProperties);
BeanComponent.getSysTaskService().updateStatus(task.getId(), ScheduledTask.TASK_STATUS_READY);
}
} else {
BeanComponent.getScheduledTask().delete(taskId);
}
}
use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.
the class SysTaskAdminController method pause.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("pause")
public String pause(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
SysTask entity = service.getEntity(id);
if (null != entity) {
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.updateStatus(id, ScheduledTask.TASK_STATUS_PAUSE);
scheduledTask.pause(site, id);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "pause.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.
the class SysTaskAdminController method save.
/**
* @param entity
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(SysTask entity, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (null != entity.getId()) {
SysTask oldEntity = service.getEntity(entity.getId());
if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
entity.setUpdateDate(CommonUtils.getDate());
entity = service.update(entity.getId(), entity, ignoreProperties);
if (null != entity) {
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
} else {
entity.setSiteId(site.getId());
service.save(entity);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
scheduledTask.create(site, entity.getId(), entity.getCronExpression());
return TEMPLATE_DONE;
}
use of com.publiccms.entities.sys.SysTask in project PublicCMS-preview by sanluan.
the class SysTaskAdminController method resume.
/**
* @param id
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("resume")
public String resume(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
SysTask entity = service.getEntity(id);
if (null != entity) {
if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
return TEMPLATE_ERROR;
}
service.updateStatus(id, ScheduledTask.TASK_STATUS_READY);
scheduledTask.resume(site, id);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "resume.task", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
}
return TEMPLATE_DONE;
}
Aggregations