all files / src/redux/actions/ taskflows.js

55.45% Statements 173/312
23.48% Branches 27/115
54.41% Functions 37/68
56.29% Lines 170/302
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554                                                  14×   14×                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DELETE_TASKFLOW = exports.BIND_SIMULATION_TO_TASKFLOW = exports.UPDATE_TASKFLOW_METADATA = exports.UPDATE_TASKFLOW_TASKS = exports.UPDATE_TASKFLOW_STATUS = exports.ADD_TASKFLOW = exports.UPDATE_TASKFLOW_TASK_STATUS = exports.UPDATE_TASKFLOW_JOB_STATUS = exports.TRIGGER_UPDATE = exports.UPDATE_TASKFLOW_TASK_LOG = exports.UPDATE_TASKFLOW_JOB_LOG = exports.GET_TASKFLOW_JOB_LOG = exports.UPDATE_TASKFLOW_LOG = exports.GET_TASKFLOW_LOG = exports.UPDATE_TASKFLOW = exports.CLEAR_UPDATE_LOG = exports.PENDING_TASKFLOW_NETWORK = undefined;
exports.pendingNetworkCall = pendingNetworkCall;
exports.clearUpdateLog = clearUpdateLog;
exports.updateTaskflowLog = updateTaskflowLog;
exports.triggerUpdate = triggerUpdate;
exports.getTaskflowLog = getTaskflowLog;
exports.updateTaskflowJobLog = updateTaskflowJobLog;
exports.getTaskflowJobLog = getTaskflowJobLog;
exports.updateTaskflowTaskLog = updateTaskflowTaskLog;
exports.updateTaskflowJobStatus = updateTaskflowJobStatus;
exports.updateTaskflowTaskStatus = updateTaskflowTaskStatus;
exports.addTaskflow = addTaskflow;
exports.attachSimulationToTaskflow = attachSimulationToTaskflow;
exports.updateTaskflowStatus = updateTaskflowStatus;
exports.updateTaskflowMetadata = updateTaskflowMetadata;
exports.startTaskflow = startTaskflow;
exports.deleteTaskflow = deleteTaskflow;
exports.createTaskflow = createTaskflow;
exports.fetchTaskflowTasks = fetchTaskflowTasks;
exports.fetchTaskflow = fetchTaskflow;
exports.updateTaskflowFromSimulation = updateTaskflowFromSimulation;
exports.terminateTaskflow = terminateTaskflow;
 
var _network = require('./network');
 
var netActions = _interopRequireWildcard(_network);
 
var _projects = require('./projects');
 
var projActions = _interopRequireWildcard(_projects);
 
var _clusters = require('./clusters');
 
var clusterActions = _interopRequireWildcard(_clusters);
 
var _progress = require('./progress');
 
var progressActions = _interopRequireWildcard(_progress);
 
var _volumes = require('./volumes');
 
var volumeActions = _interopRequireWildcard(_volumes);
 
var _network2 = require('../../network');
 
var _network3 = _interopRequireDefault(_network2);
 
var _ = require('..');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function _interopRequireWildcard(obj) { Eif (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
 
var PENDING_TASKFLOW_NETWORK = exports.PENDING_TASKFLOW_NETWORK = 'PENDING_TASKFLOW_NETWORK';
var CLEAR_UPDATE_LOG = exports.CLEAR_UPDATE_LOG = 'CLEAR_UPDATE_LOG';
var UPDATE_TASKFLOW = exports.UPDATE_TASKFLOW = 'UPDATE_TASKFLOW';
var GET_TASKFLOW_LOG = exports.GET_TASKFLOW_LOG = 'UPDATE_TASKFLOW_LOG';
var UPDATE_TASKFLOW_LOG = exports.UPDATE_TASKFLOW_LOG = 'UPDATE_TASKFLOW_LOG';
var GET_TASKFLOW_JOB_LOG = exports.GET_TASKFLOW_JOB_LOG = 'GET_TASKFLOW_JOB_LOG';
var UPDATE_TASKFLOW_JOB_LOG = exports.UPDATE_TASKFLOW_JOB_LOG = 'UPDATE_TASKFLOW_JOB_LOG';
var UPDATE_TASKFLOW_TASK_LOG = exports.UPDATE_TASKFLOW_TASK_LOG = 'UPDATE_TASKFLOW_TASK_LOG';
var TRIGGER_UPDATE = exports.TRIGGER_UPDATE = 'TRIGGER_UPDATE';
 
var UPDATE_TASKFLOW_JOB_STATUS = exports.UPDATE_TASKFLOW_JOB_STATUS = 'UPDATE_TASKFLOW_JOB_STATUS';
var UPDATE_TASKFLOW_TASK_STATUS = exports.UPDATE_TASKFLOW_TASK_STATUS = 'UPDATE_TASKFLOW_TASK_STATUS';
 
var ADD_TASKFLOW = exports.ADD_TASKFLOW = 'ADD_TASKFLOW';
var UPDATE_TASKFLOW_STATUS = exports.UPDATE_TASKFLOW_STATUS = 'UPDATE_TASKFLOW_STATUS';
var UPDATE_TASKFLOW_TASKS = exports.UPDATE_TASKFLOW_TASKS = 'UPDATE_TASKFLOW_TASKS';
var UPDATE_TASKFLOW_METADATA = exports.UPDATE_TASKFLOW_METADATA = 'UPDATE_TASKFLOW_METADATA';
var BIND_SIMULATION_TO_TASKFLOW = exports.BIND_SIMULATION_TO_TASKFLOW = 'BIND_SIMULATION_TO_TASKFLOW';
var DELETE_TASKFLOW = exports.DELETE_TASKFLOW = 'DELETE_TASKFLOW';
 
/* eslint-disable no-shadow */
 
function pendingNetworkCall(taskflowId) {
  var isPending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 
  return { type: PENDING_TASKFLOW_NETWORK, taskflowId: taskflowId, isPending: isPending };
}
 
// ----------------------------------------------------------------------------
// LOGGING
// ----------------------------------------------------------------------------
 
function clearUpdateLog() {
  return { type: CLEAR_UPDATE_LOG };
}
 
function updateTaskflowLog(taskflowId, logEntry) {
  return { type: UPDATE_TASKFLOW_LOG, taskflowId: taskflowId, logEntry: logEntry };
}
 
// this is a bit of a "force update" for StateTransitionBehavior
function triggerUpdate(taskflowId) {
  return { type: TRIGGER_UPDATE, taskflowId: taskflowId };
}
 
function getTaskflowLog(taskflowId) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('taskflow_log_' + taskflowId, 'Check taskflow log');
    _network3.default.getTaskflowLog(taskflowId).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch({ type: UPDATE_TASKFLOW_LOG, taskflowId: taskflowId, log: resp.data.log });
    }).catch(function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
    });
    return action;
  };
}
 
function updateTaskflowJobLog(taskflowId, jobId, logEntry) {
  return { type: UPDATE_TASKFLOW_JOB_LOG, taskflowId: taskflowId, jobId: jobId, logEntry: logEntry };
}
 
function getTaskflowJobLog(taskflowId, jobId) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('taskflow_job_log_' + jobId, 'Check job log');
 
    _network3.default.getJobLog(jobId).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch({
        type: GET_TASKFLOW_JOB_LOG,
        taskflowId: taskflowId,
        jobId: jobId,
        log: resp.data.log
      });
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
    });
 
    return action;
  };
}
 
function updateTaskflowTaskLog(taskflowId, taskId, logEntry) {
  return { type: UPDATE_TASKFLOW_TASK_LOG, taskflowId: taskflowId, taskId: taskId, logEntry: logEntry };
}
 
// ----------------------------------------------------------------------------
// STATUSES
function updateTaskflowJobStatus(taskflowId, jobId, status) {
  if (status) {
    return { type: UPDATE_TASKFLOW_JOB_STATUS, taskflowId: taskflowId, jobId: jobId, status: status };
  }
  return function (dispatch) {
    var action = netActions.addNetworkCall('taskflow_job_status_' + jobId, 'Check job status');
 
    _network3.default.getJobStatus(jobId).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch({
        type: UPDATE_TASKFLOW_JOB_STATUS,
        taskflowId: taskflowId,
        jobId: jobId,
        status: resp.data.status
      });
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
    });
 
    return action;
  };
}
 
function updateTaskflowTaskStatus(taskflowId, taskId, status) {
  return { type: UPDATE_TASKFLOW_TASK_STATUS, taskflowId: taskflowId, taskId: taskId, status: status };
}
 
// ----------------------------------------------------------------------------
// CRUD operations
 
function addTaskflow(taskflow) {
  var primaryJob = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
 
  return { type: ADD_TASKFLOW, taskflow: taskflow, primaryJob: primaryJob };
}
 
function attachSimulationToTaskflow(simulationId, taskflowId, stepName) {
  return {
    type: BIND_SIMULATION_TO_TASKFLOW,
    taskflowId: taskflowId,
    simulationId: simulationId,
    stepName: stepName
  };
}
 
function updateTaskflowStatus(id, status) {
  return { type: UPDATE_TASKFLOW_STATUS, id: id, status: status };
}
 
function updateTaskflowMetadata(id, metadata) {
  // metadata can have: { actions, allComplete, outputDirectory, primaryJob }
  return { type: UPDATE_TASKFLOW_METADATA, id: id, metadata: metadata };
}
 
function startTaskflow(id, payload, simulationStep, location) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('start_taskflow', 'Start taskflow');
 
    _network3.default.startTaskflow(id, payload).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      Eif (simulationStep) {
        var data = Object.assign({}, simulationStep.data, {
          metadata: Object.assign({}, simulationStep.data.metadata, {
            taskflowId: id
          })
        });
        dispatch(projActions.updateSimulationStep(simulationStep.id, simulationStep.step, data, location));
      }
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error, 'form'));
    });
 
    return action;
  };
}
 
function deleteTaskflow(taskflowId, simulationStep, location) {
  Iif (_.store.getState().taskflows.pending.indexOf(taskflowId + '_delete') !== -1) {
    return { type: 'NOOP' };
  }
  return function (dispatch) {
    var action = netActions.addNetworkCall('delete_taskflow', 'Delete taskflow');
    dispatch(pendingNetworkCall(taskflowId + '_delete', true));
    _network3.default.deleteTaskflow(taskflowId).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch({ type: DELETE_TASKFLOW, id: taskflowId });
      Iif (simulationStep) {
        dispatch(projActions.updateSimulationStep(simulationStep.id, simulationStep.step, simulationStep.data, location));
      }
      dispatch(pendingNetworkCall(taskflowId + '_delete', false));
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
    });
 
    return action;
  };
}
 
function createTaskflow(taskFlowName, primaryJob, payload, simulationStep, location) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('create_taskflow', 'Create taskflow');
 
    _network3.default.createTaskflow(taskFlowName).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch(addTaskflow(resp.data, primaryJob));
      dispatch(attachSimulationToTaskflow(simulationStep.id, resp.data._id, simulationStep.step));
      dispatch(startTaskflow(resp.data._id, payload, simulationStep, location));
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error, 'form'));
    });
 
    return action;
  };
}
 
function fetchTaskflowTasks(taskflowId) {
  Iif (_.store.getState().taskflows.pending.indexOf(taskflowId) !== -1) {
    return { type: 'NOOP' };
  }
  return function (dispatch) {
    var action = netActions.addNetworkCall('taskflow_tasks', 'Check tasks');
    dispatch(pendingNetworkCall(taskflowId, true));
    _network3.default.getTaskflowTasks(taskflowId).then(function (resp) {
      var tasks = resp.data;
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch({ type: UPDATE_TASKFLOW_TASKS, taskflowId: taskflowId, tasks: tasks });
      dispatch(pendingNetworkCall(taskflowId, false));
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
      dispatch(pendingNetworkCall(taskflowId, false));
      dispatch({ type: DELETE_TASKFLOW, id: taskflowId });
    });
 
    return action;
  };
}
 
function fetchTaskflow(id) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('taskflow_tasks', 'Check tasks');
 
    _network3.default.getTaskflow(id).then(function (resp) {
      var taskflow = resp.data;
      dispatch(netActions.successNetworkCall(action.id, resp));
      dispatch(addTaskflow(taskflow));
 
      Eif (taskflow.meta) {
        if (taskflow.meta.jobs) {
          taskflow.meta.jobs.forEach(function (job) {
            Eif (job.status !== 'complete' && job.status !== 'terminated') {
              dispatch(updateTaskflowJobStatus(id, job._id));
              dispatch(getTaskflowJobLog(id, job._id));
            }
          });
        }
        Eif (taskflow.meta.cluster) {
          clusterActions.fetchClusters();
        }
      }
    }).catch(function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error));
      dispatch({ type: DELETE_TASKFLOW, id: id });
    });
 
    dispatch(fetchTaskflowTasks(id));
 
    return action;
  };
}
 
function updateTaskflowFromSimulation(simulation) {
  return function (dispatch) {
    Object.keys(simulation.steps).forEach(function (name) {
      var taskflowId = simulation.steps[name].metadata.taskflowId;
      Eif (taskflowId) {
        dispatch(fetchTaskflow(taskflowId));
        dispatch(attachSimulationToTaskflow(simulation._id, taskflowId, name));
      }
    });
 
    return { type: 'NOOP' };
  };
}
 
function terminateTaskflow(id) {
  return function (dispatch) {
    var action = netActions.addNetworkCall('terminate_taskflow_' + id, 'Terminate taskflow');
 
    _network3.default.endTaskflow(id).then(function (resp) {
      dispatch(netActions.successNetworkCall(action.id, resp));
    }, function (error) {
      dispatch(netActions.errorNetworkCall(action.id, error, 'form'));
    });
 
    return action;
  };
}
 
// ----------------------------------------------------------------------------
// SSE Handling for taskflow, job, & task statuses
// ----------------------------------------------------------------------------
 
// find a discrete job and only update that one
function findJob(jobId) {
  var updateLog = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
 
  return function (dispatch) {
    var state = _.store.getState();
    Object.keys(state.taskflows.mapById).forEach(function (id) {
      if (state.taskflows.mapById[id].status !== 'complete' && state.taskflows.mapById[id].status !== 'terminated') {
        var action = netActions.addNetworkCall('taskflow_tasks', 'Check tasks');
        _network3.default.getTaskflow(id).then(function (resp) {
          var taskflow = resp.data;
          dispatch(netActions.successNetworkCall(action.id, resp));
          dispatch(addTaskflow(taskflow));
 
          if (taskflow.meta && taskflow.meta.jobs) {
            taskflow.meta.jobs.forEach(function (job) {
              // only update the status if the jobId is the one we're looking for
              if (job._id === jobId) {
                dispatch(updateTaskflowJobStatus(id, job._id));
                if (updateLog) {
                  dispatch(getTaskflowJobLog(id, job._id));
                }
              }
            });
          }
        }).catch(function (error) {
          dispatch(netActions.errorNetworkCall(action.id, error));
          dispatch({ type: DELETE_TASKFLOW, id: action.id });
        });
      } // close if status is (!terminated && !complete)
    });
    return { type: 'NOOP' };
  };
}
 
// fetch tasks for each taskflow, the task objects which come back have log and status.
function findTask() {
  return function (dispatch) {
    var taskflows = _.store.getState().taskflows;
    Object.keys(taskflows.mapById).forEach(function (id) {
      if (taskflows.mapById[id].status !== 'complete' && taskflows.mapById[id].status !== 'terminated') {
        dispatch(fetchTaskflowTasks(id));
      }
    });
    return { type: 'NOOP' };
  };
}
 
// updates taskflow.flow if the flow object has no meta.
// this is called when we get a cluster event for an unknown cluster
function updateTaskflowObject() {
  var state = _.store.getState();
  var taskflows = Object.keys(state.taskflows.mapById).map(function (key) {
    return state.taskflows.mapById[key];
  });
  for (var i = 0; i < taskflows.length; i++) {
    if (!taskflows[i].flow.meta && taskflows[i].flow._id) {
      (0, _.dispatch)(fetchTaskflow(taskflows[i].flow._id));
    }
  }
  (0, _.dispatch)(clusterActions.fetchClusters(null));
}
 
function getTaskflowIdFromId(id, type) {
  switch (type) {
    case 'task':
      {
        return _.store.getState().taskflows.taskflowMapByTaskId[id];
      }
    case 'job':
      {
        return _.store.getState().taskflows.taskflowMapByJobId[id];
      }
    case 'cluster':
      {
        return _.store.getState().preferences.clusters.mapById[id];
      }
    case 'profile':
      {
        return _.store.getState().preferences.clusters.mapById[id];
      }
    default:
      {
        return null;
      }
  }
}
 
function processStatusEvent(id, type, status) {
  var taskflowId = getTaskflowIdFromId(id, type);
  if (process.env.NODE_ENV !== 'production') {
    console.log(type + ' status ' + status);
  }
  if (type === 'taskflow') {
    (0, _.dispatch)(updateTaskflowStatus(id, status));
  } else if (taskflowId) {
    switch (type) {
      case 'job':
        (0, _.dispatch)(updateTaskflowJobStatus(taskflowId, id, status));
        break;
      case 'task':
        (0, _.dispatch)(updateTaskflowTaskStatus(taskflowId, id, status));
        break;
      case 'cluster':
        if (status === 'created') {
          // we need to fetch some new cluster props when this happens
          (0, _.dispatch)(clusterActions.fetchCluster(id));
        }
        (0, _.dispatch)(clusterActions.updateClusterStatus(id, status));
        break;
      case 'profile':
        (0, _.dispatch)(clusterActions.updateClusterStatus(id, status));
        break;
      case 'volume':
        (0, _.dispatch)(volumeActions.updateVolumeStatus(id, status));
        break;
      default:
        console.log('unrecognized ServerEvent with type "' + type + '",' + (' taskflowId "' + taskflowId + '", and status "' + status + '"'));
        break;
    }
  } else {
    switch (type) {
      case 'job':
        // find and update job
        (0, _.dispatch)(findJob(id));
        break;
      case 'task':
        // update all tasks for each taskflow
        (0, _.dispatch)(findTask());
        break;
      case 'cluster':
        // update taskflow meta, fetch clusters
        updateTaskflowObject();
        break;
      case 'profile':
        (0, _.dispatch)(clusterActions.fetchClusters('ec2'));
        break;
      case 'volume':
        (0, _.dispatch)(volumeActions.updateVolumeStatus(id, status));
        break;
      default:
        console.log('unrecognized ServerEvent with type "' + type + '",' + (' id "' + id + '", and status "' + status + '"'));
    }
  }
}
 
function processLogEvent(id, type, log) {
  var taskflowId = getTaskflowIdFromId(id, type);
  if (process.env.NODE_ENV !== 'production') {
    console.log(type + ' log ' + id);
  }
  if (type === 'taskflow') {
    (0, _.dispatch)(updateTaskflowLog(id, log));
  } else if (taskflowId) {
    switch (type) {
      case 'job':
        (0, _.dispatch)(updateTaskflowJobLog(taskflowId, id, log));
        break;
      case 'task':
        (0, _.dispatch)(updateTaskflowTaskLog(taskflowId, id, log));
        break;
      case 'cluster':
        (0, _.dispatch)(clusterActions.appendToClusterLog(id, log));
        break;
      case 'volume':
        (0, _.dispatch)(volumeActions.appendToVolumeLog(id, log));
        break;
      default:
        console.log('unrecognized ServerEvent with type "' + type + '",' + (' id "' + id + '", and log: '), log);
    }
  } else {
    switch (type) {
      case 'job':
        (0, _.dispatch)(findJob(id, true));
        break;
      case 'task':
        (0, _.dispatch)(findTask());
        break;
      case 'cluster':
        (0, _.dispatch)(clusterActions.fetchClusters(null));
        break;
      case 'volume':
        (0, _.dispatch)(volumeActions.fetchVolumes());
        break;
      default:
        console.log('unrecognized ServerEvent with type "' + type + '",' + (' id "' + id + '", and log: '), log);
    }
  }
}
 
_network3.default.onEvent(function (resp) {
  var type = resp.type.split('.')[0];
  var id = resp.data._id;
 
  if (resp.data.status) {
    processStatusEvent(id, type, resp.data.status);
  } else if (resp.data.log) {
    processLogEvent(id, type, resp.data.log);
  } else if (resp.type === 'progress') {
    if (process.env.NODE_ENV !== 'production') {
      console.log(resp.data.message, resp.data.current + '/' + resp.data.total);
    }
    (0, _.dispatch)(progressActions.onProgress(resp.data.current));
  }
});