Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: appengine/swarming/ui/res/imp/common/common-behavior.html

Issue 2470973003: give user notification if bot or task not found (Closed)
Patch Set: update to 1.3.1 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 It contains the definition of the following Behaviors: 6 It contains the definition of the following Behaviors:
7 7
8 SwarmingBehaviors.CommonBehavior 8 SwarmingBehaviors.CommonBehavior
9 9
10 To use it, include 10 To use it, include
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 _cloudConsoleLink: function(zone, bot_id) { 52 _cloudConsoleLink: function(zone, bot_id) {
53 return `http://console.cloud.google.com/compute/instancesDetail/zones/${ zone}/instances/${bot_id}` 53 return `http://console.cloud.google.com/compute/instancesDetail/zones/${ zone}/instances/${bot_id}`
54 }, 54 },
55 55
56 // _getJsonAsync makes an XHR to a url, parses the response as JSON 56 // _getJsonAsync makes an XHR to a url, parses the response as JSON
57 // and sticks the resulting object into the property with the name given 57 // and sticks the resulting object into the property with the name given
58 // by "bindTo". If busy is defined, the property with that name will be 58 // by "bindTo". If busy is defined, the property with that name will be
59 // set to true while the request is in flight and false afterwards. 59 // set to true while the request is in flight and false afterwards.
60 // request headers (e.g. authentication) and query params will be used if 60 // request headers (e.g. authentication) and query params will be used if
61 // provided. Query params is an object like {String:Array<String>}. On 61 // provided. Query params is an object like {String:Array<String>}. On
62 // error, bindTo will be set to false. It is not set to undefined 62 // error, bindTo will be set to false and the promise will be rejected.
63 // because computed values in Polymer don't fire if a property is 63 // It is not set to undefined because computed values in Polymer don't
64 // undefined. Clients should check that bindTo is not falsey. 64 // fire if a property is undefined.
65 // Clients should check that bindTo is not falsey.
65 // To avoid multiple requests clobering one another, an object _jsonAsync 66 // To avoid multiple requests clobering one another, an object _jsonAsync
66 // is created on "this" to debounce requests - the most recent request 67 // is created on "this" to debounce requests - the most recent request
67 // will win out. 68 // will win out.
68 _getJsonAsync: function(bindTo, url, busy, headers, params) { 69 _getJsonAsync: function(bindTo, url, busy, headers, params) {
69 if (!bindTo || !url || !busy) { 70 if (!bindTo || !url || !busy) {
70 console.log("Need at least a polymer element to bind to, a busy elemen t, and a url"); 71 console.log("Need at least a polymer element to bind to, a busy elemen t, and a url");
71 return; 72 return;
72 } 73 }
73 this.set(busy, true); 74 this.set(busy, true);
74 var now = new Date(); 75 var now = new Date();
75 this._jsonAsync = this._jsonAsync || {}; 76 this._jsonAsync = this._jsonAsync || {};
76 this._jsonAsync[bindTo] = now; 77 this._jsonAsync[bindTo] = now;
77 if (params) { 78 if (params) {
78 url = url + "?" + sk.query.fromParamSet(params); 79 url = url + "?" + sk.query.fromParamSet(params);
79 } 80 }
80 sk.request("GET", url, "", headers).then(JSON.parse).then(function(json) { 81 return sk.request("GET", url, "", headers).then(JSON.parse).then(functio n(json){
81 if (this._jsonAsync[bindTo] !== now) { 82 if (this._jsonAsync[bindTo] !== now) {
82 console.log("ignoring result because a second request happened."); 83 console.log("ignoring result because a second request happened.");
83 this.set(busy, false); 84 this.set(busy, false);
84 return; 85 return;
85 } 86 }
86 this.set(bindTo, json); 87 this.set(bindTo, json);
87 this.set(busy, false); 88 this.set(busy, false);
88 }.bind(this)).catch(function(reason){ 89 }.bind(this)).catch(function(reason){
89 console.log("Reason for failure of request to " + url, reason); 90 console.log("Reason for failure of request to " + url, reason);
90 91
91 if (this._jsonAsync[bindTo] !== now) { 92 if (this._jsonAsync[bindTo] !== now) {
92 console.log("ignoring failure because a second request happened."); 93 console.log("ignoring failure because a second request happened.");
93 this.set(busy, false); 94 this.set(busy, false);
94 return; 95 return;
95 } 96 }
96 this.set(bindTo, false); 97 this.set(bindTo, false);
97 this.set(busy, false); 98 this.set(busy, false);
99 return Promise.reject(reason);
98 }.bind(this)); 100 }.bind(this));
99 }, 101 },
100 102
101 _humanDuration: function(timeInSecs) { 103 _humanDuration: function(timeInSecs) {
102 return sk.human.strDuration(timeInSecs) || "0s"; 104 return sk.human.strDuration(timeInSecs) || "0s";
103 }, 105 },
104 106
105 _not: function(a) { 107 _not: function(a) {
106 return !a; 108 return !a;
107 }, 109 },
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 153 }
152 return this._humanDuration((second.getTime() - first.getTime())/1000); 154 return this._humanDuration((second.getTime() - first.getTime())/1000);
153 }, 155 },
154 156
155 _truthy: function(a){ 157 _truthy: function(a){
156 return !!a; 158 return !!a;
157 } 159 }
158 }; 160 };
159 })(); 161 })();
160 </script> 162 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698