-
Notifications
You must be signed in to change notification settings - Fork 4
/
taskdef.go
58 lines (42 loc) · 1.89 KB
/
taskdef.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// To avoid circular dependencies, taskdef contains the core TaskDefinition
package taskdef
import (
"time"
"github.com/anti-raid/splashtail/jobs/tasks/taskstate"
"github.com/anti-raid/splashtail/splashcore/types"
"go.uber.org/zap"
)
// TaskDefinition is the definition for any task that can be executed on splashtail
type TaskDefinition interface {
// Name returns the name of the task
Name() string
// TaskFor returns who the task is for
TaskFor() *types.TaskFor
// As tasks often deal with sensitive data such as secrets, the TaskFields method returns
// a map of fields that can be stored in the database
TaskFields() map[string]any
// Validate validates the task and sets up state if needed
Validate(state taskstate.TaskState) error
// Exec executes the task returning an output if any
Exec(l *zap.Logger, state taskstate.TaskState, progstate taskstate.TaskProgressState) (*types.TaskOutput, error)
// Expiry returns when the task will expire (if any), setting this to nil will make the task not expire
Expiry() *time.Duration
// Resumable returns whether or not the task is resumable
Resumable() bool
// CorrespondingBotCommand_View returns the bot command that should be checked for ACL purposes to list/view such a task
CorrespondingBotCommand_View() string
// CorrespondingBotCommand_Create returns the bot command that should be checked for ACL purposes to create such a task
CorrespondingBotCommand_Create() string
// CorrespondingBotCommand_Download returns the bot command that should be checked for ACL purposes to download such a task
CorrespondingBotCommand_Download() string
// LocalPresets returns the preset options of a task
LocalPresets() *PresetInfo
}
type PresetInfo struct {
// Whether or not this task should be runnable
Runnable bool
// The default options/data of the task
Preset TaskDefinition
// Any comments for specific fields
Comments map[string]string
}