Search in sources :

Example 1 with JobQueueManager

use of org.structr.core.scheduler.JobQueueManager in project structr by structr.

the class FileImportCommand method processMessage.

// ~--- methods --------------------------------------------------------
@Override
public void processMessage(WebSocketMessage webSocketData) throws FrameworkException {
    // final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final Map<String, Object> properties = webSocketData.getNodeData();
    // default: list    start | pause | resume | cancel | abort
    final String mode = (String) properties.get("mode");
    final Long jobId = (Long) properties.get("jobId");
    final JobQueueManager mgr = JobQueueManager.getInstance();
    final List<GraphObject> result = new LinkedList<>();
    switch(mode) {
        case "start":
            mgr.startJob(jobId);
            break;
        case "pause":
            mgr.pauseRunningJob(jobId);
            break;
        case "resume":
            mgr.resumePausedJob(jobId);
            break;
        case "abort":
            mgr.abortActiveJob(jobId);
            break;
        case "cancel":
            mgr.cancelQueuedJob(jobId);
            break;
        case "list":
        default:
            final GraphObjectMap importsContainer = new GraphObjectMap();
            importsContainer.put(importJobsProperty, mgr.listJobs());
            result.add(importsContainer);
    }
    webSocketData.setResult(result);
    webSocketData.setRawResultCount(1);
    getWebSocket().send(webSocketData, true);
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) GraphObject(org.structr.core.GraphObject) JobQueueManager(org.structr.core.scheduler.JobQueueManager) GraphObject(org.structr.core.GraphObject) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 GraphObject (org.structr.core.GraphObject)1 GraphObjectMap (org.structr.core.GraphObjectMap)1 JobQueueManager (org.structr.core.scheduler.JobQueueManager)1