Просмотр исходного кода

feature: Trigger another action after first action completes

jamesread 2 лет назад
Родитель
Сommit
29b6d12454
3 измененных файлов с 25 добавлено и 5 удалено
  1. 7 5
      config.yaml
  2. 1 0
      internal/config/config.go
  3. 17 0
      internal/executor/executor.go

+ 7 - 5
config.yaml

@@ -154,21 +154,23 @@ actions:
     icon: box
     shell: docker start {{ container.Names }}
     entity: container
+    trigger: Update container entity file
 
   - title: Stop {{ container.Names }}
     icon: box
     shell: docker stop {{ container.Names }}
     entity: container
+    trigger: Update container entity file
 
   # Lastly, you can hide actions from the web UI, this is useful for creating
   # background helpers that execute only on startup or a cron, for updating
   # entity files.
 
-  # - title: Update container entity file
-  #   shell: 'docker ps -a --format json > /etc/OliveTin/containers.json'
-  #   hidden: true
-  #   execOnStartup: true
-  #   execOnCron: '*/1 * * * *'
+  - title: Update container entity file
+    shell: 'docker ps -a --format json > /etc/OliveTin/entities/containers.json'
+    hidden: true
+    execOnStartup: true
+    execOnCron: '*/1 * * * *'
 
 # An entity is something that exists - a "thing", like a VM, or a Container
 # is an entity. OliveTin allows you to then dynamically generate actions based

+ 1 - 0
internal/config/config.go

@@ -17,6 +17,7 @@ type Action struct {
 	ExecOnCron             []string
 	ExecOnFileCreatedInDir []string
 	ExecOnFileChangedInDir []string
+	Trigger                string
 	MaxConcurrent          int
 	Arguments              []ActionArgument
 	PopupOnStart           string

+ 17 - 0
internal/executor/executor.go

@@ -89,6 +89,7 @@ func DefaultExecutor() *Executor {
 		stepExec,
 		stepExecAfter,
 		stepLogFinish,
+		stepTrigger,
 	}
 
 	return &e
@@ -357,3 +358,19 @@ func stepExecAfter(req *ExecutionRequest) bool {
 
 	return true
 }
+
+func stepTrigger(req *ExecutionRequest) bool {
+	if req.Action.Trigger != "" {
+		trigger := &ExecutionRequest{
+			ActionTitle:       req.Action.Trigger,
+			TrackingID:        uuid.NewString(),
+			Tags:              []string{"trigger"},
+			AuthenticatedUser: req.AuthenticatedUser,
+			Cfg:               req.Cfg,
+		}
+
+		req.executor.ExecRequest(trigger)
+	}
+
+	return true
+}