Permalink
Browse files

Make job status script to poll

Far better this way.
  • Loading branch information...
1 parent f21ca43 commit 489cf7deacc888f879bd808ea57edc9229be8063 @bebraw bebraw committed Jan 7, 2017
Showing with 24 additions and 6 deletions.
  1. +24 −6 scripts/job-status.js
View
@@ -6,10 +6,28 @@ const client = leanpub({
bookSlug: meta.bookSlug
});
-client.jobStatus(function(err, d) {
- if(err) {
- return console.error(err);
- }
+// Poll for job status now until done
+pollJobStatus(1000);
- console.log(d);
-});
+var previousMessage;
+function pollJobStatus(delay) {
+ setTimeout(function() {
+ client.jobStatus(function(err, d) {
+ if(err) {
+ return console.error(err);
+ }
+
+ if (d.status) {
+ if(previousMessage !== d.message) {
+ console.log(d.message);
+
+ previousMessage = d.message;
+ }
+
+ pollJobStatus(delay);
+ } else {
+ console.log('Done');
+ }
+ });
+ }, delay);
+}

0 comments on commit 489cf7d

Please sign in to comment.