-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Add setting to enable/disable blocking queries #5352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Controller from '@ember/controller'; | ||
import { get, set } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default Controller.extend({ | ||
repo: service('settings'), | ||
dom: service('dom'), | ||
actions: { | ||
change: function(e, value, item) { | ||
const event = get(this, 'dom').normalizeEvent(e, value); | ||
// TODO: Switch to using forms like the rest of the app | ||
// setting utils/form/builder for things to be done before we | ||
// can do that. For the moment just do things normally its a simple | ||
// enough form at the moment | ||
|
||
const target = event.target; | ||
const blocking = get(this, 'item.client.blocking'); | ||
switch (target.name) { | ||
case 'client[blocking]': | ||
if (typeof blocking === 'undefined') { | ||
set(this, 'item.client', {}); | ||
} | ||
set(this, 'item.client.blocking', !blocking); | ||
this.send('update', get(this, 'item')); | ||
break; | ||
} | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { cache as createCache, BlockingEventSource } from 'consul-ui/utils/dom/e | |
const createProxy = function(repo, find, settings, cache, serialize = JSON.stringify) { | ||
// proxied find*..(id, dc) | ||
const throttle = get(this, 'wait').execute; | ||
const client = get(this, 'client'); | ||
return function() { | ||
const key = `${repo.getModelName()}.${find}.${serialize([...arguments])}`; | ||
const _args = arguments; | ||
|
@@ -17,7 +18,7 @@ const createProxy = function(repo, find, settings, cache, serialize = JSON.strin | |
// take a copy of the original arguments | ||
// this means we don't have any configuration object on it | ||
let args = [..._args]; | ||
if (settings.blocking) { | ||
if (configuration.settings.enabled) { | ||
// ...and only add our current cursor/configuration if we are blocking | ||
args = args.concat([configuration]); | ||
} | ||
|
@@ -26,7 +27,7 @@ const createProxy = function(repo, find, settings, cache, serialize = JSON.strin | |
// original find... with configuration now added | ||
return repo[find](...args) | ||
.then(res => { | ||
if (!settings.blocking) { | ||
if (!configuration.settings.enabled) { | ||
// blocking isn't enabled, immediately close | ||
this.close(); | ||
} | ||
|
@@ -38,20 +39,27 @@ const createProxy = function(repo, find, settings, cache, serialize = JSON.strin | |
const status = get(e, 'errors.firstObject.status'); | ||
if (status === '0') { | ||
// Any '0' errors (abort) should possibly try again, depending upon the circumstances | ||
// whenAvailable returns a Promise that resolves when the client is available | ||
// again | ||
return client.whenAvailable(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns a Promise which resolves when the client (tab) becomes available again. As this is all based on a recurring Promise this essentially pauses the blocking query when the status of the error is zero (aborted) and then resolves the promise, and hence restarts the blocking query. |
||
} | ||
throw e; | ||
}); | ||
}; | ||
// if we have a cursor (which means its at least the second call) | ||
// and we have a throttle setting, wait for so many ms | ||
if (typeof configuration.cursor !== 'undefined' && settings.throttle) { | ||
return throttle(settings.throttle).then(cb); | ||
if (typeof configuration.cursor !== 'undefined' && configuration.settings.throttle) { | ||
return throttle(configuration.settings.throttle).then(cb); | ||
} | ||
return cb(); | ||
}, | ||
{ | ||
key: key, | ||
type: BlockingEventSource, | ||
settings: { | ||
enabled: settings.blocking, | ||
throttle: settings.throttle, | ||
}, | ||
} | ||
); | ||
}; | ||
|
@@ -61,6 +69,7 @@ export default LazyProxyService.extend({ | |
store: service('store'), | ||
settings: service('settings'), | ||
wait: service('timeout'), | ||
client: service('client/http'), | ||
init: function() { | ||
this._super(...arguments); | ||
if (cache === null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
{{#hashicorp-consul id="wrapper" dcs=dcs dc=dc}} | ||
{{#app-view class="settings show"}} | ||
{{#block-slot 'notification' as |status type|}} | ||
{{#if (eq type 'update')}} | ||
{{#if (eq status 'success') }} | ||
Your settings were saved. | ||
{{else}} | ||
There was an error saving your settings. | ||
{{/if}} | ||
{{ else if (eq type 'delete')}} | ||
{{#if (eq status 'success') }} | ||
You settings have been reset. | ||
{{else}} | ||
There was an error resetting your settings. | ||
{{/if}} | ||
{{/if}} | ||
{{/block-slot}} | ||
{{#block-slot 'header'}} | ||
<h1> | ||
Settings | ||
|
@@ -26,13 +11,13 @@ | |
</p> | ||
<form> | ||
<fieldset> | ||
<label class="type-text"> | ||
<span>ACL Token</span> | ||
{{ input type='password' value=item.token name="token" }} | ||
<em>The token is sent with requests as the <code>X-Consul-Token</code> HTTP header parameter. This is used to control the ACL for the web UI.</em> | ||
</label> | ||
<div class="type-toggle"> | ||
<label> | ||
<input type="checkbox" name="client[blocking]" checked={{if item.client.blocking 'checked' }} onchange={{action 'change'}} /> | ||
<span>Enable Catalog realtime updates (blocking queries)</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to be specific what this does as I've no idea when this will land in a release. We may be able to add in blocking queries to the rest of the app before then, we may not. |
||
</label> | ||
</div> | ||
</fieldset> | ||
<button type="submit" {{action 'update' item}}>Save</button> | ||
</form> | ||
{{/block-slot}} | ||
{{/app-view}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
|
||
moduleFor('controller:settings', 'Unit | Controller | settings', { | ||
// Specify the other units that are required for this test. | ||
needs: ['service:settings', 'service:dom'], | ||
}); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let controller = this.subject(); | ||
assert.ok(controller); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've included an id argument here, to remind us at some point that it maybe useful to be able to
abort
individual connections here. We initially named itabortAll
, and then changed to justabort
when we figured this might be useful.