Search in sources :

Example 6 with SysTask

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);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) SysTask(com.publiccms.entities.sys.SysTask) IOException(java.io.IOException) Date(java.util.Date) SysSite(com.publiccms.entities.sys.SysSite) LogTask(com.publiccms.entities.log.LogTask)

Example 7 with SysTask

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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with SysTask

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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with SysTask

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;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysTask(com.publiccms.entities.sys.SysTask) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysSite (com.publiccms.entities.sys.SysSite)9 SysTask (com.publiccms.entities.sys.SysTask)9 LogOperate (com.publiccms.entities.log.LogOperate)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 LogTask (com.publiccms.entities.log.LogTask)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1