1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 23:04:21 +00:00

🔧 Handle errors when syncing DataFlows

This commit is contained in:
Steffo 2021-04-19 23:40:06 +02:00
parent f673bc0818
commit 349a3aaf8e
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 30 additions and 4 deletions

View file

@ -1,4 +1,4 @@
from django.contrib import admin
from django.contrib import admin, messages
from . import models
@ -25,11 +25,26 @@ class ProjectAdmin(CoreAdmin):
)
@admin.action(description="Syncronize DataFlows (slow, be patient!)")
@admin.action(description="Sync DataFlows")
def sync_flows_admin(modeladmin, request, queryset):
for datasource in queryset:
datasource: models.DataSource
try:
datasource.sync_flows()
except NotImplementedError:
modeladmin.message_user(
request,
f"Skipped {datasource}: Syncing DataFlows is not supported on this DataSource.",
level=messages.ERROR
)
except Exception as exc:
modeladmin.message_user(
request,
f"Skipped {datasource}: {exc}",
level=messages.ERROR
)
else:
modeladmin.log_change(request, datasource, "Sync DataFlows")
@admin.register(models.DataSource)

View file

@ -68,7 +68,18 @@ class DataSourceViewSet(viewsets.ModelViewSet):
log.debug(f"Getting DataSource from the database...")
db_datasource: models.DataSource = self.get_object()
try:
db_datasource.sync_flows()
except NotImplementedError:
return response.Response({
"success": False,
"error": "Syncing DataFlows is not supported on this DataSource."
})
except Exception as exc:
return response.Response({
"success": False,
"error": f"{exc}"
})
return response.Response({
"success": True,