stash/pkg/plugin/task.go

49 lines
1.1 KiB
Go
Raw Normal View History

2020-08-08 02:05:35 +00:00
package plugin
import (
2021-05-26 04:17:53 +00:00
"net/http"
2020-08-08 02:05:35 +00:00
"github.com/stashapp/stash/pkg/plugin/common"
)
// Task is the interface that handles management of a single plugin task.
type Task interface {
// Start starts the plugin task. Returns an error if task could not be
// started or the task has already been started.
Start() error
// Stop instructs a running plugin task to stop and returns immediately.
// Use Wait to subsequently wait for the task to stop.
Stop() error
// Wait blocks until the plugin task is complete. Returns immediately if
// task has not been started.
Wait()
// GetResult returns the output of the plugin task. Returns nil if the task
// has not completed.
GetResult() *common.PluginOutput
}
type taskBuilder interface {
build(task pluginTask) Task
}
type pluginTask struct {
plugin *Config
operation *OperationConfig
input common.PluginInput
gqlHandler http.Handler
2020-08-08 02:05:35 +00:00
progress chan float64
result *common.PluginOutput
}
func (t *pluginTask) GetResult() *common.PluginOutput {
return t.result
}
func (t *pluginTask) createTask() Task {
return t.plugin.Interface.getTaskBuilder().build(*t)
}