Last active
May 31, 2016 16:07
-
-
Save Mariusio/f240f25b5819289805b743c09b06d238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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