{"action":"created","comment":{"url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/comments/32374930","id":32374930,"diff_hunk":"@@ -61,36 +61,89 @@ var TaskModel = Backbone.Model.extend({\n         }\n     },\n \n+    // Cancels any currently running jobs. The promise returned\n+    // by previous calls to pollForResults will be rejected.\n+    reset: function() {\n+        this.set({\n+            'job': null,\n+            'result': null,\n+            'status': null\n+        });\n+    },\n+\n+    // taskHelper should be an object containing an optional object,\n+    // postData, an optional function, onStart, and functions pollSuccess,\n+    // pollFailure, and startFailure.\n+    start: function(taskHelper) {\n+        this.reset();\n+        if (taskHelper.onStart) {\n+            taskHelper.onStart();\n+        }\n+        var self = this;\n+\n+        self\n+            .fetch({\n+                method: 'POST',\n+                data: taskHelper.postData\n+            })\n+            .done(function() {\n+                self.pollForResults()\n+                    .done(function() {\n+                        taskHelper.pollSuccess();\n+                    })\n+                    .fail(function(failure) {\n+                        if (failure && failure.reset) {\n+                            console.log('Job ' + failure.reset.job + ' was cancelled.');\n+                        } else {\n+                            taskHelper.pollFailure();\n+                        }\n+                    });\n+            })\n+            .fail(function() {\n+                taskHelper.startFailure();\n+            });\n+    },\n+\n     pollForResults: function() {\n         var defer = $.Deferred(),\n             duration = 0,\n-            self = this;\n+            self = this,\n+            expectedJob = self.get('job');\n \n         // Check the task endpoint to see if the job is\n         // completed. If it is, return the results of\n         // the job. If not, check again after\n         // pollInterval has elapsed.\n         var getResults = function() {\n-                if (duration >= self.get('timeout')) {\n-                    defer.reject();\n-                    return;\n-                }\n+            if (duration >= self.get('timeout')) {\n+                defer.reject();\n+                return;\n+            }\n \n-                self.fetch()\n-                    .done(function(response) {\n-                        console.log('Polling ' + self.url());\n-                        if (response.status !== 'complete') {\n-                            duration = duration + self.get('pollInterval');\n-                            window.setTimeout(getResults, self.get('pollInterval'));\n-                        } else {\n-                            defer.resolve(response);\n-                        }\n-                    })\n-                    .fail(defer.reject);\n+            // If job was cancelled.\n+            if (expectedJob != self.get('job')) {\n+                defer.reject({\n+                    reset: {","path":"src/mmw/js/src/core/models.js","position":82,"original_position":82,"commit_id":"80fd6f462bd6e36ab49ba5a39b5b8a3366d37ded","original_commit_id":"80fd6f462bd6e36ab49ba5a39b5b8a3366d37ded","user":{"login":"kdeloach","id":43062,"avatar_url":"https://avatars.githubusercontent.com/u/43062?v=3","gravatar_id":"","url":"https://api.github.com/users/kdeloach","html_url":"https://github.com/kdeloach","followers_url":"https://api.github.com/users/kdeloach/followers","following_url":"https://api.github.com/users/kdeloach/following{/other_user}","gists_url":"https://api.github.com/users/kdeloach/gists{/gist_id}","starred_url":"https://api.github.com/users/kdeloach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kdeloach/subscriptions","organizations_url":"https://api.github.com/users/kdeloach/orgs","repos_url":"https://api.github.com/users/kdeloach/repos","events_url":"https://api.github.com/users/kdeloach/events{/privacy}","received_events_url":"https://api.github.com/users/kdeloach/received_events","type":"User","site_admin":false},"body":"Consider flattening this data structure, if possible. IMO `reject({ reset: { job: ... } })` isn't more descriptive than `reject(expectedJob)` or maybe even `reject(expectedJob + ' was cancelled')`.","created_at":"2015-06-13T23:44:16Z","updated_at":"2015-06-13T23:44:16Z","html_url":"https://github.com/WikiWatershed/model-my-watershed/pull/345#discussion_r32374930","pull_request_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345","_links":{"self":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/comments/32374930"},"html":{"href":"https://github.com/WikiWatershed/model-my-watershed/pull/345#discussion_r32374930"},"pull_request":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345"}}},"pull_request":{"url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345","id":37308130,"html_url":"https://github.com/WikiWatershed/model-my-watershed/pull/345","diff_url":"https://github.com/WikiWatershed/model-my-watershed/pull/345.diff","patch_url":"https://github.com/WikiWatershed/model-my-watershed/pull/345.patch","issue_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/345","number":345,"state":"open","locked":false,"title":"Associate model output with scenario window","user":{"login":"lewfish","id":1896461,"avatar_url":"https://avatars.githubusercontent.com/u/1896461?v=3","gravatar_id":"","url":"https://api.github.com/users/lewfish","html_url":"https://github.com/lewfish","followers_url":"https://api.github.com/users/lewfish/followers","following_url":"https://api.github.com/users/lewfish/following{/other_user}","gists_url":"https://api.github.com/users/lewfish/gists{/gist_id}","starred_url":"https://api.github.com/users/lewfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewfish/subscriptions","organizations_url":"https://api.github.com/users/lewfish/orgs","repos_url":"https://api.github.com/users/lewfish/repos","events_url":"https://api.github.com/users/lewfish/events{/privacy}","received_events_url":"https://api.github.com/users/lewfish/received_events","type":"User","site_admin":false},"body":"Reprovision the worker VM. (Although running `sudo service celeryd restart` and `pip install -r src/mmw/requirements/base.txt` (to install tr55) on the worker VM will probably suffice.)\r\n\r\nMake sure that the analyze view still loads table/chart as before.\r\n\r\nIn the model view, in Current Conditions, set the value of the precipitation slider. This should start the spinner icon on the Runoff tab. After polling ~6 times, the bar chart should display with the total level of runoff/et/inf matching the selected precipitation value, and the spinner should stop.\r\n\r\nTry changing the precipitation value once, and then again about a second later. On the console, you should see that the first job was cancelled. If the user submits several jobs within the time it takes to run the model, there will be multiple jobs in the queue ahead of the final job, delaying the final job, potentially past the time limit set in the TaskModel. I think we should create a separate issue to deal with cancelling jobs on the backend.\r\n\r\nTry making a new scenario, and change the precip values in both scenarios so they are polling concurrently. This should work. Adding modifications will fire off the job, but the modifications will have no effect because we don't have the Geotrellis task running on the backend yet.\r\n\r\nConnects #200 ","created_at":"2015-06-09T22:40:45Z","updated_at":"2015-06-13T23:44:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"09578ff992720134525c67932f7efb0285dd6474","assignee":{"login":"lewfish","id":1896461,"avatar_url":"https://avatars.githubusercontent.com/u/1896461?v=3","gravatar_id":"","url":"https://api.github.com/users/lewfish","html_url":"https://github.com/lewfish","followers_url":"https://api.github.com/users/lewfish/followers","following_url":"https://api.github.com/users/lewfish/following{/other_user}","gists_url":"https://api.github.com/users/lewfish/gists{/gist_id}","starred_url":"https://api.github.com/users/lewfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewfish/subscriptions","organizations_url":"https://api.github.com/users/lewfish/orgs","repos_url":"https://api.github.com/users/lewfish/repos","events_url":"https://api.github.com/users/lewfish/events{/privacy}","received_events_url":"https://api.github.com/users/lewfish/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345/commits","review_comments_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345/comments","review_comment_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/345/comments","statuses_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/statuses/80fd6f462bd6e36ab49ba5a39b5b8a3366d37ded","head":{"label":"lewfish:feature/run-model","ref":"feature/run-model","sha":"80fd6f462bd6e36ab49ba5a39b5b8a3366d37ded","user":{"login":"lewfish","id":1896461,"avatar_url":"https://avatars.githubusercontent.com/u/1896461?v=3","gravatar_id":"","url":"https://api.github.com/users/lewfish","html_url":"https://github.com/lewfish","followers_url":"https://api.github.com/users/lewfish/followers","following_url":"https://api.github.com/users/lewfish/following{/other_user}","gists_url":"https://api.github.com/users/lewfish/gists{/gist_id}","starred_url":"https://api.github.com/users/lewfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewfish/subscriptions","organizations_url":"https://api.github.com/users/lewfish/orgs","repos_url":"https://api.github.com/users/lewfish/repos","events_url":"https://api.github.com/users/lewfish/events{/privacy}","received_events_url":"https://api.github.com/users/lewfish/received_events","type":"User","site_admin":false},"repo":{"id":36329041,"name":"model-my-watershed","full_name":"lewfish/model-my-watershed","owner":{"login":"lewfish","id":1896461,"avatar_url":"https://avatars.githubusercontent.com/u/1896461?v=3","gravatar_id":"","url":"https://api.github.com/users/lewfish","html_url":"https://github.com/lewfish","followers_url":"https://api.github.com/users/lewfish/followers","following_url":"https://api.github.com/users/lewfish/following{/other_user}","gists_url":"https://api.github.com/users/lewfish/gists{/gist_id}","starred_url":"https://api.github.com/users/lewfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewfish/subscriptions","organizations_url":"https://api.github.com/users/lewfish/orgs","repos_url":"https://api.github.com/users/lewfish/repos","events_url":"https://api.github.com/users/lewfish/events{/privacy}","received_events_url":"https://api.github.com/users/lewfish/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lewfish/model-my-watershed","description":"The web application front end for Model My Watershed.","fork":true,"url":"https://api.github.com/repos/lewfish/model-my-watershed","forks_url":"https://api.github.com/repos/lewfish/model-my-watershed/forks","keys_url":"https://api.github.com/repos/lewfish/model-my-watershed/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lewfish/model-my-watershed/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lewfish/model-my-watershed/teams","hooks_url":"https://api.github.com/repos/lewfish/model-my-watershed/hooks","issue_events_url":"https://api.github.com/repos/lewfish/model-my-watershed/issues/events{/number}","events_url":"https://api.github.com/repos/lewfish/model-my-watershed/events","assignees_url":"https://api.github.com/repos/lewfish/model-my-watershed/assignees{/user}","branches_url":"https://api.github.com/repos/lewfish/model-my-watershed/branches{/branch}","tags_url":"https://api.github.com/repos/lewfish/model-my-watershed/tags","blobs_url":"https://api.github.com/repos/lewfish/model-my-watershed/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lewfish/model-my-watershed/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lewfish/model-my-watershed/git/refs{/sha}","trees_url":"https://api.github.com/repos/lewfish/model-my-watershed/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lewfish/model-my-watershed/statuses/{sha}","languages_url":"https://api.github.com/repos/lewfish/model-my-watershed/languages","stargazers_url":"https://api.github.com/repos/lewfish/model-my-watershed/stargazers","contributors_url":"https://api.github.com/repos/lewfish/model-my-watershed/contributors","subscribers_url":"https://api.github.com/repos/lewfish/model-my-watershed/subscribers","subscription_url":"https://api.github.com/repos/lewfish/model-my-watershed/subscription","commits_url":"https://api.github.com/repos/lewfish/model-my-watershed/commits{/sha}","git_commits_url":"https://api.github.com/repos/lewfish/model-my-watershed/git/commits{/sha}","comments_url":"https://api.github.com/repos/lewfish/model-my-watershed/comments{/number}","issue_comment_url":"https://api.github.com/repos/lewfish/model-my-watershed/issues/comments{/number}","contents_url":"https://api.github.com/repos/lewfish/model-my-watershed/contents/{+path}","compare_url":"https://api.github.com/repos/lewfish/model-my-watershed/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lewfish/model-my-watershed/merges","archive_url":"https://api.github.com/repos/lewfish/model-my-watershed/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lewfish/model-my-watershed/downloads","issues_url":"https://api.github.com/repos/lewfish/model-my-watershed/issues{/number}","pulls_url":"https://api.github.com/repos/lewfish/model-my-watershed/pulls{/number}","milestones_url":"https://api.github.com/repos/lewfish/model-my-watershed/milestones{/number}","notifications_url":"https://api.github.com/repos/lewfish/model-my-watershed/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lewfish/model-my-watershed/labels{/name}","releases_url":"https://api.github.com/repos/lewfish/model-my-watershed/releases{/id}","created_at":"2015-05-26T23:05:44Z","updated_at":"2015-05-26T23:06:34Z","pushed_at":"2015-06-12T20:46:10Z","git_url":"git://github.com/lewfish/model-my-watershed.git","ssh_url":"git@github.com:lewfish/model-my-watershed.git","clone_url":"https://github.com/lewfish/model-my-watershed.git","svn_url":"https://github.com/lewfish/model-my-watershed","homepage":null,"size":13588,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"WikiWatershed:develop","ref":"develop","sha":"80cd1294e02b564b28378de8135e7cb6f5cba999","user":{"login":"WikiWatershed","id":8520008,"avatar_url":"https://avatars.githubusercontent.com/u/8520008?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiWatershed","html_url":"https://github.com/WikiWatershed","followers_url":"https://api.github.com/users/WikiWatershed/followers","following_url":"https://api.github.com/users/WikiWatershed/following{/other_user}","gists_url":"https://api.github.com/users/WikiWatershed/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiWatershed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiWatershed/subscriptions","organizations_url":"https://api.github.com/users/WikiWatershed/orgs","repos_url":"https://api.github.com/users/WikiWatershed/repos","events_url":"https://api.github.com/users/WikiWatershed/events{/privacy}","received_events_url":"https://api.github.com/users/WikiWatershed/received_events","type":"Organization","site_admin":false},"repo":{"id":32742922,"name":"model-my-watershed","full_name":"WikiWatershed/model-my-watershed","owner":{"login":"WikiWatershed","id":8520008,"avatar_url":"https://avatars.githubusercontent.com/u/8520008?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiWatershed","html_url":"https://github.com/WikiWatershed","followers_url":"https://api.github.com/users/WikiWatershed/followers","following_url":"https://api.github.com/users/WikiWatershed/following{/other_user}","gists_url":"https://api.github.com/users/WikiWatershed/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiWatershed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiWatershed/subscriptions","organizations_url":"https://api.github.com/users/WikiWatershed/orgs","repos_url":"https://api.github.com/users/WikiWatershed/repos","events_url":"https://api.github.com/users/WikiWatershed/events{/privacy}","received_events_url":"https://api.github.com/users/WikiWatershed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WikiWatershed/model-my-watershed","description":"The web application front end for Model My Watershed.","fork":false,"url":"https://api.github.com/repos/WikiWatershed/model-my-watershed","forks_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/forks","keys_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/teams","hooks_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/hooks","issue_events_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/events{/number}","events_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/events","assignees_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/assignees{/user}","branches_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/branches{/branch}","tags_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/tags","blobs_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/git/refs{/sha}","trees_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/statuses/{sha}","languages_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/languages","stargazers_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/stargazers","contributors_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/contributors","subscribers_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/subscribers","subscription_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/subscription","commits_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/commits{/sha}","git_commits_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/git/commits{/sha}","comments_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/comments{/number}","issue_comment_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/comments{/number}","contents_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/contents/{+path}","compare_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/merges","archive_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/downloads","issues_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues{/number}","pulls_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls{/number}","milestones_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/milestones{/number}","notifications_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/labels{/name}","releases_url":"https://api.github.com/repos/WikiWatershed/model-my-watershed/releases{/id}","created_at":"2015-03-23T16:02:55Z","updated_at":"2015-06-11T19:29:19Z","pushed_at":"2015-06-12T21:43:43Z","git_url":"git://github.com/WikiWatershed/model-my-watershed.git","ssh_url":"git@github.com:WikiWatershed/model-my-watershed.git","clone_url":"https://github.com/WikiWatershed/model-my-watershed.git","svn_url":"https://github.com/WikiWatershed/model-my-watershed","homepage":null,"size":15747,"stargazers_count":2,"watchers_count":2,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":112,"forks":9,"open_issues":112,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345"},"html":{"href":"https://github.com/WikiWatershed/model-my-watershed/pull/345"},"issue":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/345"},"comments":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/issues/345/comments"},"review_comments":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345/comments"},"review_comment":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/pulls/345/commits"},"statuses":{"href":"https://api.github.com/repos/WikiWatershed/model-my-watershed/statuses/80fd6f462bd6e36ab49ba5a39b5b8a3366d37ded"}}}}