mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-3905: fix comments
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
parent
aa0b73e9b0
commit
a883c37b39
2 changed files with 30 additions and 9 deletions
|
@ -68,6 +68,9 @@ type Import struct {
|
|||
fileSync filesync.FileSync
|
||||
notificationService notifications.Notifications
|
||||
eventSender event.Sender
|
||||
|
||||
importCtx context.Context
|
||||
importCtxCancel context.CancelFunc
|
||||
}
|
||||
|
||||
func New() Importer {
|
||||
|
@ -105,16 +108,29 @@ func (i *Import) Init(a *app.App) (err error) {
|
|||
i.fileSync = app.MustComponent[filesync.FileSync](a)
|
||||
i.notificationService = app.MustComponent[notifications.Notifications](a)
|
||||
i.eventSender = app.MustComponent[event.Sender](a)
|
||||
|
||||
i.importCtx, i.importCtxCancel = context.WithCancel(context.Background())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Import) Run(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (i *Import) Close(ctx context.Context) (err error) {
|
||||
if i.importCtxCancel != nil {
|
||||
i.importCtxCancel()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Import get snapshots from converter or external api and create smartblocks from them
|
||||
func (i *Import) Import(ctx context.Context, importRequest *ImportRequest) *ImportResponse {
|
||||
if importRequest.IsSync {
|
||||
return i.importObjects(ctx, importRequest)
|
||||
}
|
||||
go conc.Go(func() {
|
||||
res := i.importObjects(context.Background(), importRequest)
|
||||
conc.Go(func() {
|
||||
res := i.importObjects(i.importCtx, importRequest)
|
||||
if res.Err != nil {
|
||||
log.Errorf("import from %s failed with error: %s", importRequest.Type.String(), res.Err)
|
||||
}
|
||||
|
@ -144,7 +160,10 @@ func (i *Import) importObjects(ctx context.Context, importRequest *ImportRequest
|
|||
i.onImportFinish(res, importRequest, importId)
|
||||
}()
|
||||
if i.s != nil && !importRequest.GetNoProgress() && isNewProgress {
|
||||
i.s.ProcessAdd(importRequest.Progress)
|
||||
err := i.s.ProcessAdd(importRequest.Progress)
|
||||
if err != nil {
|
||||
return &ImportResponse{Err: fmt.Errorf("failed to add process")}
|
||||
}
|
||||
}
|
||||
i.recordEvent(&metrics.ImportStartedEvent{ID: importId, ImportType: importRequest.Type.String()})
|
||||
res.Err = fmt.Errorf("unknown import type %s", importRequest.Type)
|
||||
|
|
|
@ -37,14 +37,16 @@ func MapErr[T, R any](input []T, f func(T) (R, error)) ([]R, error) {
|
|||
}
|
||||
|
||||
func Go(fn func()) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if rerr, ok := r.(error); ok {
|
||||
OnPanic(rerr)
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if rerr, ok := r.(error); ok {
|
||||
OnPanic(rerr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
fn()
|
||||
}()
|
||||
fn()
|
||||
}
|
||||
|
||||
func OnPanic(v any) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue