Fix how keys are stored for luigi overnight/backfill tasks

This commit is contained in:
Lance Edgar 2022-11-20 13:58:39 -06:00
parent d4801f58e3
commit 7f0305fb7a
2 changed files with 54 additions and 42 deletions

View file

@ -29,6 +29,10 @@
<!-- sortable> -->
<!-- {{ props.row.key }} -->
<!-- </b-table-column> -->
<b-table-column field="key"
label="Key">
{{ props.row.key }}
</b-table-column>
<b-table-column field="description"
label="Description">
{{ props.row.description }}
@ -63,11 +67,12 @@
</header>
<section class="modal-card-body">
<!-- <b-field label="Key"> -->
<!-- <b-input v-model.trim="overnightTaskKey" -->
<!-- ref="overnightTaskKey"> -->
<!-- </b-input> -->
<!-- </b-field> -->
<b-field label="Key"
:type="overnightTaskKey ? null : 'is-danger'">
<b-input v-model.trim="overnightTaskKey"
ref="overnightTaskKey">
</b-input>
</b-field>
<b-field label="Description"
:type="overnightTaskDescription ? null : 'is-danger'">
<b-input v-model.trim="overnightTaskDescription"
@ -91,7 +96,7 @@
icon-pack="fas"
icon-left="save"
@click="overnightTaskSave()"
:disabled="!overnightTaskDescription || !overnightTaskScript">
:disabled="!overnightTaskKey || !overnightTaskDescription || !overnightTaskScript">
Save
</b-button>
<b-button @click="overnightTaskShowDialog = false">
@ -122,6 +127,10 @@
<b-table :data="backfillTasks">
<template slot-scope="props">
<b-table-column field="key"
label="Key">
{{ props.row.key }}
</b-table-column>
<b-table-column field="description"
label="Description">
{{ props.row.description }}
@ -164,6 +173,12 @@
</header>
<section class="modal-card-body">
<b-field label="Key"
:type="backfillTaskKey ? null : 'is-danger'">
<b-input v-model.trim="backfillTaskKey"
ref="backfillTaskKey">
</b-input>
</b-field>
<b-field label="Description"
:type="backfillTaskDescription ? null : 'is-danger'">
<b-input v-model.trim="backfillTaskDescription"
@ -199,7 +214,7 @@
icon-pack="fas"
icon-left="save"
@click="backfillTaskSave()"
:disabled="!backfillTaskDescription || !backfillTaskScript">
:disabled="!backfillTaskKey || !backfillTaskDescription || !backfillTaskScript">
Save
</b-button>
<b-button @click="backfillTaskShowDialog = false">
@ -259,14 +274,14 @@
ThisPageData.overnightTaskNotes = null
ThisPage.methods.overnightTaskCreate = function() {
this.overnightTask = {key: null}
this.overnightTask = {key: null, isNew: true}
this.overnightTaskKey = null
this.overnightTaskDescription = null
this.overnightTaskScript = null
this.overnightTaskNotes = null
this.overnightTaskShowDialog = true
this.$nextTick(() => {
this.$refs.overnightTaskDescription.focus()
this.$refs.overnightTaskKey.focus()
})
}
@ -280,13 +295,14 @@
}
ThisPage.methods.overnightTaskSave = function() {
this.overnightTask.key = this.overnightTaskKey
this.overnightTask.description = this.overnightTaskDescription
this.overnightTask.script = this.overnightTaskScript
this.overnightTask.notes = this.overnightTaskNotes
if (!this.overnightTask.key) {
this.overnightTask.key = `_new_${'$'}{++this.overnightTaskCounter}`
if (this.overnightTask.isNew) {
this.overnightTasks.push(this.overnightTask)
this.overnightTask.isNew = false
}
this.overnightTaskShowDialog = false
@ -313,7 +329,8 @@
ThisPageData.backfillTaskNotes = null
ThisPage.methods.backfillTaskCreate = function() {
this.backfillTask = {key: null}
this.backfillTask = {key: null, isNew: true}
this.backfillTaskKey = null
this.backfillTaskDescription = null
this.backfillTaskScript = null
this.backfillTaskForward = false
@ -321,12 +338,13 @@
this.backfillTaskNotes = null
this.backfillTaskShowDialog = true
this.$nextTick(() => {
this.$refs.backfillTaskDescription.focus()
this.$refs.backfillTaskKey.focus()
})
}
ThisPage.methods.backfillTaskEdit = function(task) {
this.backfillTask = task
this.backfillTaskKey = task.key
this.backfillTaskDescription = task.description
this.backfillTaskScript = task.script
this.backfillTaskForward = task.forward
@ -344,15 +362,16 @@
}
ThisPage.methods.backfillTaskSave = function() {
this.backfillTask.key = this.backfillTaskKey
this.backfillTask.description = this.backfillTaskDescription
this.backfillTask.script = this.backfillTaskScript
this.backfillTask.forward = this.backfillTaskForward
this.backfillTask.target_date = this.backfillTaskTargetDate
this.backfillTask.notes = this.backfillTaskNotes
if (!this.backfillTask.key) {
this.backfillTask.key = `_new_${'$'}{++this.backfillTaskCounter}`
if (this.backfillTask.isNew) {
this.backfillTasks.push(this.backfillTask)
this.backfillTask.isNew = false
}
this.backfillTaskShowDialog = false

View file

@ -166,56 +166,39 @@ class LuigiTaskView(MasterView):
# overnight tasks
keys = []
for task in json.loads(data['overnight_tasks']):
key = task['key']
if key.startswith('_new_'):
key = app.make_uuid()
key = task['key']
if key.startswith('_new_'):
cmd = shlex.split(task['script'])
script = os.path.basename(cmd[0])
root, ext = os.path.splitext(script)
key = re.sub(r'\s+', '-', root)
keys.append(key)
settings.extend([
{'name': 'rattail.luigi.overnight.{}.description'.format(key),
{'name': 'rattail.luigi.overnight.task.{}.description'.format(key),
'value': task['description']},
{'name': 'rattail.luigi.overnight.{}.script'.format(key),
{'name': 'rattail.luigi.overnight.task.{}.script'.format(key),
'value': task['script']},
{'name': 'rattail.luigi.overnight.{}.notes'.format(key),
{'name': 'rattail.luigi.overnight.task.{}.notes'.format(key),
'value': task['notes']},
])
if keys:
settings.append({'name': 'rattail.luigi.overnight_tasks',
settings.append({'name': 'rattail.luigi.overnight.tasks',
'value': ', '.join(keys)})
# backfill tasks
keys = []
for task in json.loads(data['backfill_tasks']):
key = task['key']
if key.startswith('_new_'):
script = os.path.basename(task['script'])
root, ext = os.path.splitext(script)
key = re.sub(r'\s+', '-', root)
keys.append(key)
settings.extend([
{'name': 'rattail.luigi.backfill.{}.description'.format(key),
{'name': 'rattail.luigi.backfill.task.{}.description'.format(key),
'value': task['description']},
{'name': 'rattail.luigi.backfill.{}.script'.format(key),
{'name': 'rattail.luigi.backfill.task.{}.script'.format(key),
'value': task['script']},
{'name': 'rattail.luigi.backfill.{}.forward'.format(key),
{'name': 'rattail.luigi.backfill.task.{}.forward'.format(key),
'value': 'true' if task['forward'] else 'false'},
{'name': 'rattail.luigi.backfill.{}.notes'.format(key),
{'name': 'rattail.luigi.backfill.task.{}.notes'.format(key),
'value': task['notes']},
{'name': 'rattail.luigi.backfill.{}.target_date'.format(key),
{'name': 'rattail.luigi.backfill.task.{}.target_date'.format(key),
'value': six.text_type(task['target_date'])},
])
if keys:
settings.append({'name': 'rattail.luigi.backfill_tasks',
settings.append({'name': 'rattail.luigi.backfill.tasks',
'value': ', '.join(keys)})
return settings
@ -228,15 +211,25 @@ class LuigiTaskView(MasterView):
to_delete = session.query(model.Setting)\
.filter(sa.or_(
model.Setting.name == 'rattail.luigi.backfill.tasks',
model.Setting.name == 'rattail.luigi.backfill_tasks',
model.Setting.name.like('rattail.luigi.backfill.task.%.description'),
model.Setting.name.like('rattail.luigi.backfill.%.description'),
model.Setting.name.like('rattail.luigi.backfill.task.%.forward'),
model.Setting.name.like('rattail.luigi.backfill.%.forward'),
model.Setting.name.like('rattail.luigi.backfill.task.%.notes'),
model.Setting.name.like('rattail.luigi.backfill.%.notes'),
model.Setting.name.like('rattail.luigi.backfill.task.%.script'),
model.Setting.name.like('rattail.luigi.backfill.%.script'),
model.Setting.name.like('rattail.luigi.backfill.task.%.target_date'),
model.Setting.name.like('rattail.luigi.backfill.%.target_date'),
model.Setting.name == 'rattail.luigi.overnight.tasks',
model.Setting.name == 'rattail.luigi.overnight_tasks',
model.Setting.name.like('rattail.luigi.overnight.task.%.description'),
model.Setting.name.like('rattail.luigi.overnight.%.description'),
model.Setting.name.like('rattail.luigi.overnight.task.%.notes'),
model.Setting.name.like('rattail.luigi.overnight.%.notes'),
model.Setting.name.like('rattail.luigi.overnight.task.%.script'),
model.Setting.name.like('rattail.luigi.overnight.%.script')))\
.all()