Code coverage report for src/flux/job.coffee

Statements: 73.53% (25 / 34)      Branches: 44.44% (8 / 18)      Functions: 80% (4 / 5)      Lines: 73.53% (25 / 34)      Ignored: none     

All files » src/flux/ » job.coffee
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                                                                                                    
var CrudConfig, JobConfig, _, actions, extendConfig, makeSimpleStore, ref, ref1, store;
 
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
 
_ = require('underscore');
 
JobConfig = {
  _checkUntil: {},
  _loaded: function(obj, id) {
    var checkJob, count, finalStatus, interval, jobData, maxRepeats, previousJobData, ref1;
    Eif (this._checkUntil[id] != null) {
      ref1 = this._checkUntil[id], finalStatus = ref1.finalStatus, checkJob = ref1.checkJob, count = ref1.count, maxRepeats = ref1.maxRepeats, interval = ref1.interval;
      this._checkUntil[id].count = count + 1;
      jobData = _.extend({}, obj, {
        id: id
      });
      Iif (!((finalStatus.indexOf(jobData.status) > -1) || this._checkUntil[id].count > maxRepeats)) {
        previousJobData = this._get(id);
        if ((previousJobData != null ? previousJobData.status : void 0) !== obj.status) {
          this.emit("job." + id + ".updated", jobData);
        }
        setTimeout(checkJob, interval);
      } else {
        this.emit("job." + id + ".final", jobData);
        delete this._checkUntil[id];
      }
    }
    return jobData;
  },
  _failed: function(obj, id) {
    return this.loaded(obj, id);
  },
  checkUntil: function(id, checkJob, interval, maxRepeats, finalStatus) {
    Iif (interval == null) {
      interval = 1000;
    }
    Iif (maxRepeats == null) {
      maxRepeats = 50;
    }
    Eif (finalStatus == null) {
      finalStatus = ['succeeded', 'failed', 'killed', 404];
    }
    if (this._checkUntil[id] == null) {
      this._checkUntil[id] = {
        checkJob: checkJob,
        finalStatus: finalStatus,
        interval: interval,
        maxRepeats: maxRepeats,
        count: 0
      };
      return checkJob();
    }
  },
  stopChecking: function(id) {
    return delete this._checkUntil[id];
  },
  exports: {
    getStatus: function(id) {
      var status;
      status = this._get(id).status;
      return status;
    }
  }
};
 
extendConfig(JobConfig, new CrudConfig());
 
ref1 = makeSimpleStore(JobConfig), actions = ref1.actions, store = ref1.store;
 
module.exports = {
  JobActions: actions,
  JobStore: store
};