mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add plugin tasks (#651)
This commit is contained in:
56
pkg/plugin/task.go
Normal file
56
pkg/plugin/task.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"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
|
||||
serverConnection common.StashServerConnection
|
||||
args []*models.PluginArgInput
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (t *pluginTask) buildPluginInput() common.PluginInput {
|
||||
args := applyDefaultArgs(t.args, t.operation.DefaultArgs)
|
||||
t.serverConnection.PluginDir = t.plugin.getConfigPath()
|
||||
return common.PluginInput{
|
||||
ServerConnection: t.serverConnection,
|
||||
Args: toPluginArgs(args),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user