stash/internal/manager/task_plugin.go
WithoutPants a6f15273d9
Improve Windows stash behaviour (#2543)
* Rename manager.instance to Manager
* Show dialog message on fatal error on Windows
* Hide console windows explicitly on icon launch

Gets rid of the windowsgui flag, which causes all sorts of issues.
Instead, checks if stash was launched from the icon, and if so hides the console.

* Remove fixconsole
* Add changelog entries
2022-05-04 10:37:32 +10:00

60 lines
1.4 KiB
Go

package manager
import (
"context"
"fmt"
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
)
func (s *Manager) RunPluginTask(ctx context.Context, pluginID string, taskName string, args []*models.PluginArgInput) int {
j := job.MakeJobExec(func(jobCtx context.Context, progress *job.Progress) {
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
}
err = task.Start()
if err != nil {
logger.Errorf("Error running plugin task: %s", err.Error())
return
}
done := make(chan bool)
go func() {
defer close(done)
task.Wait()
output := task.GetResult()
if output == nil {
logger.Debug("Plugin returned no result")
} else {
if output.Error != nil {
logger.Errorf("Plugin returned error: %s", *output.Error)
} else if output.Output != nil {
logger.Debugf("Plugin returned: %v", output.Output)
}
}
}()
for {
select {
case <-done:
return
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 s.JobManager.Add(ctx, fmt.Sprintf("Running plugin task: %s", taskName), j)
}