Skip to content

Commit 77d9c5e

Browse files
committed
clean the pipeline storage
1 parent cd24f50 commit 77d9c5e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

learn2rag/ui/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,16 @@ def pipeline_action(name: str) -> 'str | werkzeug.wrappers.response.Response':
443443
app.logger.exception(e)
444444
app.logger.error('Could not stop the pipeline')
445445
flash(pgettext('flash', 'Could not stop the pipeline: %(message)s', message=e), 'error')
446+
elif request.form['action'] == 'clean':
447+
try:
448+
storage_path = expand_path(pipeline['storage_path'])
449+
shutil.rmtree(storage_path)
450+
flash(pgettext('flash', 'Successfully clean the pipeline storage: '), 'success')
451+
except FileNotFoundError:
452+
pass
453+
except Exception as e:
454+
app.logger.error('Failed to remove directory: %s, %s', storage_path, e)
455+
flash(pgettext('flash', 'Could not clean the pipeline storage: %(message)s', message=e), 'error')
446456
return redirect(url_for('pipelines_list'))
447457

448458
@app.get('/pipelines/<name>/logs/<file>')

learn2rag/ui/templates/_pipelines_list_table.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@
102102
</button>
103103
</form>
104104
</li>
105+
<li><hr class="dropdown-divider"></li>
106+
<li>
107+
<form method="POST" action="{{ url_for('pipeline_action', name=name) }}" hx-boost="true" hx-confirm="{{gettext('Are you sure you want to clean this pipeline storage: %(label)s?', label=pipeline.label)}}">
108+
<input type="hidden" name="action" value="clean"/>
109+
<button type="submit" class="dropdown-item text-bg-danger">
110+
{{pgettext('button', 'Clean storage')}}
111+
</button>
112+
</form>
113+
</li>
105114
</ul>
106115
</div>
107116
{% endif %}

0 commit comments

Comments
 (0)