Allow configuring datasync watcher kwargs
This commit is contained in:
parent
87cced1637
commit
7b2fef5f09
|
@ -218,9 +218,111 @@
|
|||
</b-input>
|
||||
</b-field>
|
||||
|
||||
<b-field :label="`Kwargs (${'$'}{editingProfilePendingWatcherKwargs.length})`">
|
||||
<b-button type="is-primary"
|
||||
icon-pack="fas"
|
||||
icon-left="edit"
|
||||
:disabled="editingWatcherKwarg"
|
||||
@click="editingWatcherKwargs = !editingWatcherKwargs">
|
||||
{{ editingWatcherKwargs ? "Stop Editing" : "Edit Kwargs" }}
|
||||
</b-button>
|
||||
</b-field>
|
||||
|
||||
<div style="display: flex;">
|
||||
</b-field>
|
||||
|
||||
<div v-show="editingWatcherKwargs"
|
||||
style="display: flex; justify-content: end;">
|
||||
|
||||
<b-button type="is-primary"
|
||||
v-show="!editingWatcherKwarg"
|
||||
icon-pack="fas"
|
||||
icon-left="plus"
|
||||
@click="newWatcherKwarg()">
|
||||
New Watcher Kwarg
|
||||
</b-button>
|
||||
|
||||
<div v-show="editingWatcherKwarg">
|
||||
|
||||
<b-field grouped>
|
||||
|
||||
<b-field label="Key"
|
||||
:type="editingWatcherKwargKey ? null : 'is-danger'">
|
||||
<b-input v-model="editingWatcherKwargKey"
|
||||
ref="watcherKwargKey">
|
||||
</b-input>
|
||||
</b-field>
|
||||
|
||||
<b-field label="Value"
|
||||
:type="editingWatcherKwargValue ? null : 'is-danger'">
|
||||
<b-input v-model="editingWatcherKwargValue">
|
||||
</b-input>
|
||||
</b-field>
|
||||
|
||||
</b-field>
|
||||
|
||||
<b-field grouped>
|
||||
|
||||
<b-button @click="editingWatcherKwarg = null"
|
||||
class="control"
|
||||
>
|
||||
Cancel
|
||||
</b-button>
|
||||
|
||||
<b-button type="is-primary"
|
||||
@click="updateWatcherKwarg()"
|
||||
class="control">
|
||||
Update Kwarg
|
||||
</b-button>
|
||||
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<b-table :data="editingProfilePendingWatcherKwargs"
|
||||
style="margin-left: 1rem;">
|
||||
<template slot-scope="props">
|
||||
<b-table-column field="key" label="Key">
|
||||
{{ props.row.key }}
|
||||
</b-table-column>
|
||||
<b-table-column field="value" label="Value">
|
||||
{{ props.row.value }}
|
||||
</b-table-column>
|
||||
<b-table-column label="Actions">
|
||||
<a href="#"
|
||||
@click.prevent="editProfileWatcherKwarg(props.row)">
|
||||
<i class="fas fa-edit"></i>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
<a href="#"
|
||||
class="has-text-danger"
|
||||
@click.prevent="deleteProfileWatcherKwarg(props.row)">
|
||||
<i class="fas fa-trash"></i>
|
||||
Delete
|
||||
</a>
|
||||
</b-table-column>
|
||||
</template>
|
||||
<template slot="empty">
|
||||
<section class="section">
|
||||
<div class="content has-text-grey has-text-centered">
|
||||
<p>
|
||||
<b-icon
|
||||
pack="fas"
|
||||
icon="fas fa-sad-tear"
|
||||
size="is-large">
|
||||
</b-icon>
|
||||
</p>
|
||||
<p>Nothing here.</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</b-table>
|
||||
|
||||
</div>
|
||||
|
||||
<div v-show="!editingWatcherKwargs"
|
||||
style="display: flex;">
|
||||
|
||||
<div style="width: 40%;">
|
||||
|
||||
|
@ -512,6 +614,7 @@
|
|||
ThisPage.methods.newProfile = function() {
|
||||
this.editingProfile = {}
|
||||
this.editingConsumer = null
|
||||
this.editingWatcherKwargs = false
|
||||
|
||||
this.editingProfileKey = null
|
||||
this.editingProfileWatcherSpec = null
|
||||
|
@ -523,6 +626,7 @@
|
|||
this.editingProfileWatcherConsumesSelf = false
|
||||
this.editingProfileEnabled = true
|
||||
this.editingProfilePendingConsumers = []
|
||||
this.editingProfilePendingWatcherKwargs = []
|
||||
|
||||
this.editProfileShowDialog = true
|
||||
this.$nextTick(() => {
|
||||
|
@ -533,6 +637,7 @@
|
|||
ThisPage.methods.editProfile = function(row) {
|
||||
this.editingProfile = row
|
||||
this.editingConsumer = null
|
||||
this.editingWatcherKwargs = false
|
||||
|
||||
this.editingProfileKey = row.key
|
||||
this.editingProfileWatcherSpec = row.watcher_spec
|
||||
|
@ -544,6 +649,16 @@
|
|||
this.editingProfileWatcherConsumesSelf = row.watcher_consumes_self
|
||||
this.editingProfileEnabled = row.enabled
|
||||
|
||||
this.editingProfilePendingWatcherKwargs = []
|
||||
for (let kwarg of row.watcher_kwargs_data) {
|
||||
let pending = {
|
||||
original_key: kwarg.key,
|
||||
key: kwarg.key,
|
||||
value: kwarg.value,
|
||||
}
|
||||
this.editingProfilePendingWatcherKwargs.push(pending)
|
||||
}
|
||||
|
||||
this.editingProfilePendingConsumers = []
|
||||
for (let consumer of row.consumers_data) {
|
||||
let pending = {
|
||||
|
@ -563,6 +678,46 @@
|
|||
this.editProfileShowDialog = true
|
||||
}
|
||||
|
||||
ThisPageData.editingWatcherKwargs = false
|
||||
ThisPageData.editingProfilePendingWatcherKwargs = []
|
||||
ThisPageData.editingWatcherKwarg = null
|
||||
ThisPageData.editingWatcherKwargKey = null
|
||||
ThisPageData.editingWatcherKwargValue = null
|
||||
|
||||
ThisPage.methods.newWatcherKwarg = function() {
|
||||
this.editingWatcherKwargKey = null
|
||||
this.editingWatcherKwargValue = null
|
||||
this.editingWatcherKwarg = {key: null, value: null}
|
||||
this.$nextTick(() => {
|
||||
this.$refs.watcherKwargKey.focus()
|
||||
})
|
||||
}
|
||||
|
||||
ThisPage.methods.editProfileWatcherKwarg = function(row) {
|
||||
this.editingWatcherKwargKey = row.key
|
||||
this.editingWatcherKwargValue = row.value
|
||||
this.editingWatcherKwarg = row
|
||||
}
|
||||
|
||||
ThisPage.methods.updateWatcherKwarg = function() {
|
||||
let pending = this.editingWatcherKwarg
|
||||
let isNew = !pending.key
|
||||
|
||||
pending.key = this.editingWatcherKwargKey
|
||||
pending.value = this.editingWatcherKwargValue
|
||||
|
||||
if (isNew) {
|
||||
this.editingProfilePendingWatcherKwargs.push(pending)
|
||||
}
|
||||
|
||||
this.editingWatcherKwarg = null
|
||||
}
|
||||
|
||||
ThisPage.methods.deleteProfileWatcherKwarg = function(row) {
|
||||
let i = this.editingProfilePendingWatcherKwargs.indexOf(row)
|
||||
this.editingProfilePendingWatcherKwargs.splice(i, 1)
|
||||
}
|
||||
|
||||
ThisPage.methods.findOriginalConsumer = function(key) {
|
||||
for (let consumer of this.editingProfile.consumers_data) {
|
||||
if (consumer.key == key) {
|
||||
|
@ -590,11 +745,39 @@
|
|||
row.enabled = this.editingProfileEnabled
|
||||
|
||||
// track which keys still belong (persistent)
|
||||
let persistent = []
|
||||
let persistentWatcherKwargs = []
|
||||
|
||||
// transfer pending data to profile watcher kwargs
|
||||
for (let pending of this.editingProfilePendingWatcherKwargs) {
|
||||
persistentWatcherKwargs.push(pending.key)
|
||||
if (pending.original_key) {
|
||||
let kwarg = this.findOriginalWatcherKwarg(pending.original_key)
|
||||
kwarg.key = pending.key
|
||||
kwarg.value = pending.value
|
||||
} else {
|
||||
row.watcher_kwargs_data.push(pending)
|
||||
}
|
||||
}
|
||||
|
||||
// remove any kwargs not being persisted
|
||||
let removeWatcherKwargs = []
|
||||
for (let kwarg of row.watcher_kwargs_data) {
|
||||
let i = persistentWatcherKwargs.indexOf(kwarg.key)
|
||||
if (i < 0) {
|
||||
removeWatcherKwargs.push(kwarg)
|
||||
}
|
||||
}
|
||||
for (let kwarg of removeWatcherKwargs) {
|
||||
let i = row.watcher_kwargs_data.indexOf(kwarg)
|
||||
row.watcher_kwargs_data.splice(i, 1)
|
||||
}
|
||||
|
||||
// track which keys still belong (persistent)
|
||||
let persistentConsumers = []
|
||||
|
||||
// transfer pending data to profile consumers
|
||||
for (let pending of this.editingProfilePendingConsumers) {
|
||||
persistent.push(pending.key)
|
||||
persistentConsumers.push(pending.key)
|
||||
if (pending.original_key) {
|
||||
let consumer = this.findOriginalConsumer(pending.original_key)
|
||||
consumer.key = pending.key
|
||||
|
@ -611,14 +794,14 @@
|
|||
}
|
||||
|
||||
// remove any consumers not being persisted
|
||||
let remove = []
|
||||
let removeConsumers = []
|
||||
for (let consumer of row.consumers_data) {
|
||||
let i = persistent.indexOf(consumer.key)
|
||||
let i = persistentConsumers.indexOf(consumer.key)
|
||||
if (i < 0) {
|
||||
remove.push(consumer)
|
||||
removeConsumers.push(consumer)
|
||||
}
|
||||
}
|
||||
for (let consumer of remove) {
|
||||
for (let consumer of removeConsumers) {
|
||||
let i = row.consumers_data.indexOf(consumer)
|
||||
row.consumers_data.splice(i, 1)
|
||||
}
|
||||
|
|
|
@ -86,10 +86,10 @@ class WebsocketView(object):
|
|||
|
||||
# use given db session, or make a new one
|
||||
with app.short_session(config=self.rattail_config,
|
||||
session=session):
|
||||
session=session) as s:
|
||||
|
||||
# load user proper
|
||||
return session.query(model.User).get(user_uuid)
|
||||
return s.query(model.User).get(user_uuid)
|
||||
|
||||
def get_user_session(self, scope):
|
||||
settings = self.registry.settings
|
||||
|
|
|
@ -202,6 +202,9 @@ class DataSyncThreadView(MasterView):
|
|||
'watcher_retry_delay': profile.watcher.retry_delay,
|
||||
'watcher_default_runas': profile.watcher.default_runas,
|
||||
'watcher_consumes_self': profile.watcher.consumes_self,
|
||||
'watcher_kwargs_data': [{'key': key,
|
||||
'value': profile.watcher_kwargs[key]}
|
||||
for key in sorted(profile.watcher_kwargs)],
|
||||
# 'notes': None, # TODO
|
||||
'enabled': profile.enabled,
|
||||
}
|
||||
|
@ -227,8 +230,7 @@ class DataSyncThreadView(MasterView):
|
|||
return {
|
||||
'profiles': profiles,
|
||||
'profiles_data': profiles_data,
|
||||
'use_profile_settings': self.rattail_config.getbool(
|
||||
'rattail.datasync', 'use_profile_settings'),
|
||||
'use_profile_settings': self.datasync_handler.should_use_profile_settings(),
|
||||
'supervisor_process_name': self.rattail_config.get(
|
||||
'rattail.datasync', 'supervisor_process_name'),
|
||||
'restart_command': self.rattail_config.get(
|
||||
|
@ -265,6 +267,13 @@ class DataSyncThreadView(MasterView):
|
|||
'value': profile['watcher_default_runas']},
|
||||
])
|
||||
|
||||
for kwarg in profile['watcher_kwargs_data']:
|
||||
settings.append({
|
||||
'name': 'rattail.datasync.{}.watcher.kwarg.{}'.format(
|
||||
pkey, kwarg['key']),
|
||||
'value': kwarg['value'],
|
||||
})
|
||||
|
||||
consumers = []
|
||||
if profile['watcher_consumes_self']:
|
||||
consumers = ['self']
|
||||
|
@ -298,9 +307,11 @@ class DataSyncThreadView(MasterView):
|
|||
settings.append({'name': 'rattail.datasync.watch',
|
||||
'value': ', '.join(watch)})
|
||||
|
||||
if data['supervisor_process_name']:
|
||||
settings.append({'name': 'rattail.datasync.supervisor_process_name',
|
||||
'value': data['supervisor_process_name']})
|
||||
|
||||
if data['restart_command']:
|
||||
settings.append({'name': 'tailbone.datasync.restart',
|
||||
'value': data['restart_command']})
|
||||
|
||||
|
|
Loading…
Reference in a new issue