mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user