mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
* 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
60 lines
1.4 KiB
Go
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)
|
|
}
|