Make migration an asynchronous task (#4666)

* Add failed state and error to Job
* Move migration code
* Add websocket monitor
* Make migrate a job managed task
This commit is contained in:
WithoutPants
2024-03-14 11:06:23 +11:00
committed by GitHub
parent fa172c2dfd
commit e5929389b4
36 changed files with 693 additions and 304 deletions

View File

@@ -16,18 +16,16 @@ func (s *Manager) RunPluginTask(
description *string,
args plugin.OperationInput,
) int {
j := job.MakeJobExec(func(jobCtx context.Context, progress *job.Progress) {
j := job.MakeJobExec(func(jobCtx context.Context, progress *job.Progress) error {
pluginProgress := make(chan float64)
task, err := s.PluginCache.CreateTask(ctx, pluginID, taskName, args, pluginProgress)
if err != nil {
logger.Errorf("Error creating plugin task: %s", err.Error())
return
return fmt.Errorf("Error creating plugin task: %w", err)
}
err = task.Start()
if err != nil {
logger.Errorf("Error running plugin task: %s", err.Error())
return
return fmt.Errorf("Error running plugin task: %w", err)
}
done := make(chan bool)
@@ -50,14 +48,14 @@ func (s *Manager) RunPluginTask(
for {
select {
case <-done:
return
return nil
case p := <-pluginProgress:
progress.SetPercent(p)
case <-jobCtx.Done():
if err := task.Stop(); err != nil {
logger.Errorf("Error stopping plugin operation: %s", err.Error())
}
return
return nil
}
}
})