Skip to content

Instantly share code, notes, and snippets.

@Mariusio
Last active May 31, 2016 16:07
Show Gist options
  • Save Mariusio/f240f25b5819289805b743c09b06d238 to your computer and use it in GitHub Desktop.
Save Mariusio/f240f25b5819289805b743c09b06d238 to your computer and use it in GitHub Desktop.
// app/services/pusher.js
channel.bind('executionStatus', (payload) => {
// find report with this executionId
const reports = this.get('store').peekAll('report');
reports.forEach((report) => {
if (report.get('executionId') === payload.execution_id) {
if (payload.event === 'success') {
// execute getExecutionStatusTask
report.get('getExecutionStatusTask').cancelAll();
report.get('getExecutionStatusTask').perform();
}
}
});
});
// app/models/report.js
getExecutionStatus() {
return this.get('ajax').request('/executions/' + this.get('executionId') + '/status');
},
getExecutionStatusTask: task(function * () {
try {
let result = yield this.getExecutionStatus();
Ember.Logger.debug(result);
if (result.running) {
// still running, try again after timeout
yield timeout(2000);
this.get('getExecutionStatusTask').perform();
} else if (result.status === 'success') {
// proceed..
}
} catch (error) {
Ember.Logger.error(error);
}
}).drop(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment