mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 14:54:22 +00:00
🔧 Handle errors when syncing DataFlows
This commit is contained in:
parent
2b8fe4ee65
commit
45fff68bd2
2 changed files with 30 additions and 4 deletions
|
@ -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
|
||||
datasource.sync_flows()
|
||||
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)
|
||||
|
|
|
@ -68,7 +68,18 @@ class DataSourceViewSet(viewsets.ModelViewSet):
|
|||
|
||||
log.debug(f"Getting DataSource from the database...")
|
||||
db_datasource: models.DataSource = self.get_object()
|
||||
db_datasource.sync_flows()
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue