Allow configuring datasync watcher kwargs
This commit is contained in:
parent
87cced1637
commit
7b2fef5f09
|
@ -218,9 +218,111 @@
|
||||||
</b-input>
|
</b-input>
|
||||||
</b-field>
|
</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>
|
||||||
|
|
||||||
</b-field>
|
</b-field>
|
||||||
|
|
||||||
<div style="display: flex;">
|
<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%;">
|
<div style="width: 40%;">
|
||||||
|
|
||||||
|
@ -512,6 +614,7 @@
|
||||||
ThisPage.methods.newProfile = function() {
|
ThisPage.methods.newProfile = function() {
|
||||||
this.editingProfile = {}
|
this.editingProfile = {}
|
||||||
this.editingConsumer = null
|
this.editingConsumer = null
|
||||||
|
this.editingWatcherKwargs = false
|
||||||
|
|
||||||
this.editingProfileKey = null
|
this.editingProfileKey = null
|
||||||
this.editingProfileWatcherSpec = null
|
this.editingProfileWatcherSpec = null
|
||||||
|
@ -523,6 +626,7 @@
|
||||||
this.editingProfileWatcherConsumesSelf = false
|
this.editingProfileWatcherConsumesSelf = false
|
||||||
this.editingProfileEnabled = true
|
this.editingProfileEnabled = true
|
||||||
this.editingProfilePendingConsumers = []
|
this.editingProfilePendingConsumers = []
|
||||||
|
this.editingProfilePendingWatcherKwargs = []
|
||||||
|
|
||||||
this.editProfileShowDialog = true
|
this.editProfileShowDialog = true
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
@ -533,6 +637,7 @@
|
||||||
ThisPage.methods.editProfile = function(row) {
|
ThisPage.methods.editProfile = function(row) {
|
||||||
this.editingProfile = row
|
this.editingProfile = row
|
||||||
this.editingConsumer = null
|
this.editingConsumer = null
|
||||||
|
this.editingWatcherKwargs = false
|
||||||
|
|
||||||
this.editingProfileKey = row.key
|
this.editingProfileKey = row.key
|
||||||
this.editingProfileWatcherSpec = row.watcher_spec
|
this.editingProfileWatcherSpec = row.watcher_spec
|
||||||
|
@ -544,6 +649,16 @@
|
||||||
this.editingProfileWatcherConsumesSelf = row.watcher_consumes_self
|
this.editingProfileWatcherConsumesSelf = row.watcher_consumes_self
|
||||||
this.editingProfileEnabled = row.enabled
|
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 = []
|
this.editingProfilePendingConsumers = []
|
||||||
for (let consumer of row.consumers_data) {
|
for (let consumer of row.consumers_data) {
|
||||||
let pending = {
|
let pending = {
|
||||||
|
@ -563,6 +678,46 @@
|
||||||
this.editProfileShowDialog = true
|
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) {
|
ThisPage.methods.findOriginalConsumer = function(key) {
|
||||||
for (let consumer of this.editingProfile.consumers_data) {
|
for (let consumer of this.editingProfile.consumers_data) {
|
||||||
if (consumer.key == key) {
|
if (consumer.key == key) {
|
||||||
|
@ -590,11 +745,39 @@
|
||||||
row.enabled = this.editingProfileEnabled
|
row.enabled = this.editingProfileEnabled
|
||||||
|
|
||||||
// track which keys still belong (persistent)
|
// 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
|
// transfer pending data to profile consumers
|
||||||
for (let pending of this.editingProfilePendingConsumers) {
|
for (let pending of this.editingProfilePendingConsumers) {
|
||||||
persistent.push(pending.key)
|
persistentConsumers.push(pending.key)
|
||||||
if (pending.original_key) {
|
if (pending.original_key) {
|
||||||
let consumer = this.findOriginalConsumer(pending.original_key)
|
let consumer = this.findOriginalConsumer(pending.original_key)
|
||||||
consumer.key = pending.key
|
consumer.key = pending.key
|
||||||
|
@ -611,14 +794,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove any consumers not being persisted
|
// remove any consumers not being persisted
|
||||||
let remove = []
|
let removeConsumers = []
|
||||||
for (let consumer of row.consumers_data) {
|
for (let consumer of row.consumers_data) {
|
||||||
let i = persistent.indexOf(consumer.key)
|
let i = persistentConsumers.indexOf(consumer.key)
|
||||||
if (i < 0) {
|
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)
|
let i = row.consumers_data.indexOf(consumer)
|
||||||
row.consumers_data.splice(i, 1)
|
row.consumers_data.splice(i, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,10 @@ class WebsocketView(object):
|
||||||
|
|
||||||
# use given db session, or make a new one
|
# use given db session, or make a new one
|
||||||
with app.short_session(config=self.rattail_config,
|
with app.short_session(config=self.rattail_config,
|
||||||
session=session):
|
session=session) as s:
|
||||||
|
|
||||||
# load user proper
|
# 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):
|
def get_user_session(self, scope):
|
||||||
settings = self.registry.settings
|
settings = self.registry.settings
|
||||||
|
|
|
@ -202,6 +202,9 @@ class DataSyncThreadView(MasterView):
|
||||||
'watcher_retry_delay': profile.watcher.retry_delay,
|
'watcher_retry_delay': profile.watcher.retry_delay,
|
||||||
'watcher_default_runas': profile.watcher.default_runas,
|
'watcher_default_runas': profile.watcher.default_runas,
|
||||||
'watcher_consumes_self': profile.watcher.consumes_self,
|
'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
|
# 'notes': None, # TODO
|
||||||
'enabled': profile.enabled,
|
'enabled': profile.enabled,
|
||||||
}
|
}
|
||||||
|
@ -227,8 +230,7 @@ class DataSyncThreadView(MasterView):
|
||||||
return {
|
return {
|
||||||
'profiles': profiles,
|
'profiles': profiles,
|
||||||
'profiles_data': profiles_data,
|
'profiles_data': profiles_data,
|
||||||
'use_profile_settings': self.rattail_config.getbool(
|
'use_profile_settings': self.datasync_handler.should_use_profile_settings(),
|
||||||
'rattail.datasync', 'use_profile_settings'),
|
|
||||||
'supervisor_process_name': self.rattail_config.get(
|
'supervisor_process_name': self.rattail_config.get(
|
||||||
'rattail.datasync', 'supervisor_process_name'),
|
'rattail.datasync', 'supervisor_process_name'),
|
||||||
'restart_command': self.rattail_config.get(
|
'restart_command': self.rattail_config.get(
|
||||||
|
@ -265,6 +267,13 @@ class DataSyncThreadView(MasterView):
|
||||||
'value': profile['watcher_default_runas']},
|
'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 = []
|
consumers = []
|
||||||
if profile['watcher_consumes_self']:
|
if profile['watcher_consumes_self']:
|
||||||
consumers = ['self']
|
consumers = ['self']
|
||||||
|
@ -298,11 +307,13 @@ class DataSyncThreadView(MasterView):
|
||||||
settings.append({'name': 'rattail.datasync.watch',
|
settings.append({'name': 'rattail.datasync.watch',
|
||||||
'value': ', '.join(watch)})
|
'value': ', '.join(watch)})
|
||||||
|
|
||||||
settings.append({'name': 'rattail.datasync.supervisor_process_name',
|
if data['supervisor_process_name']:
|
||||||
'value': data['supervisor_process_name']})
|
settings.append({'name': 'rattail.datasync.supervisor_process_name',
|
||||||
|
'value': data['supervisor_process_name']})
|
||||||
|
|
||||||
settings.append({'name': 'tailbone.datasync.restart',
|
if data['restart_command']:
|
||||||
'value': data['restart_command']})
|
settings.append({'name': 'tailbone.datasync.restart',
|
||||||
|
'value': data['restart_command']})
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue