Sha256: dd37f53fe05a6ee38820b0f76118f84228c564c066ba765bae401f43079a81a8

Contents?: true

Size: 1020 Bytes

Versions: 8

Compression:

Stored size: 1020 Bytes

Contents

(function() {

  var self = JobState = {};

  self.startPolling = function(options) {
    self._jobUuid = options.jobUuid;
    self._updateFn = options.update;
    self._successFn = options.success;
    self._errorFn = options.error;
    self._pollingPeriod = options.pollingPeriod || 1000;
    self._poll();
  };

  self._poll = function() {
    setTimeout(function() {
      $.ajax({
        url: '/job_state/job_states/' + self._jobUuid,
        type: 'GET',
        dataType: 'json',
        success: function(data) {
          if (data.job_state == 'success') {
            if (self._successFn) {
              self._successFn(data);
            }
          }
          else if (data.job_state == 'error') {
            if (self._errorFn) {
              self._errorFn(data);
            }
          }
          else {
            if (self._updateFn) {
              self._updateFn(data);
            }
            self._poll(self._jobUuid);
          }
        }
      });
    }, self._pollingPeriod);
  };

}());

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
job_state-0.0.12 app/assets/javascripts/job_state/job-state.js
job_state-0.0.11 app/assets/javascripts/job_state/job-state.js
job_state-0.0.10 app/assets/javascripts/job_state/job-state.js
job_state-0.0.9 app/assets/javascripts/job_state/job-state.js
job_state-0.0.7 app/assets/javascripts/job_state/job-state.js
job_state-0.0.6 app/assets/javascripts/job_state/job-state.js
job_state-0.0.5 app/assets/javascripts/job_state/job-state.js
job_state-0.0.4 app/assets/javascripts/job_state/job-state.js