重构 指令

master
dengsgo 2020-03-03 11:37:20 +08:00
parent f989590d14
commit b72caedcbb
6 changed files with 56 additions and 47 deletions

View File

@ -130,19 +130,6 @@ command:
# 如果不需要该特性,设置为 0
delayMillSecond: 2000
# 特殊指令
# 可以通过预定义的指令来控制 command 的行为,指令可以有多个
# exec-when-start fileboy启动就绪后自动执行一次 'exec' 定义的命令
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出,直到有明确 exit code 才会开始执行本次命令。
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
# ignore-warn fileboy 自身的 warn 信息会被丢弃
# ignore-info fileboy 自身的 info 信息会被丢弃
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
instruction:
#- should-finish
#- exec-when-start
# 通知器
notifier:
# 文件更改会向该 url 发送请求POST 一段 json 文本数据)
@ -155,6 +142,22 @@ notifier:
# 例: http://example.com/notifier/fileboy-listener
# 不启用通知,请留空 ""
callUrl: ""
# 特殊指令
instruction:
# 可以通过特殊的指令选项来控制 command 的行为,指令可以有多个
# 指令选项解释:
# exec-when-start fileboy启动就绪后自动执行一次 'exec' 定义的命令
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出(而不是强制 kill ),直到 L 有明确 exit code 才会开始执行本次命令。
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
# ignore-warn fileboy 自身的 warn 信息会被丢弃
# ignore-info fileboy 自身的 info 信息会被丢弃
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
#- should-finish
#- exec-when-start
- ignore-warn
```
### TODO

View File

@ -127,19 +127,6 @@ command:
# If this feature is not required, set to 0
delayMillSecond: 2000
# 特殊指令
# 可以通过预定义的指令来控制 command 的行为,指令可以有多个
# exec-when-start fileboy启动就绪后自动执行一次 'exec' 定义的命令
# should-finish 触发执行 'exec' 时(C),如果上一次的命令(L)未退出(还在执行),会等待 L 退出,直到有明确 exit code 才会开始执行本次命令。
# 在等待 L 退出时,又有新事件触发了命令执行(N),则 C 执行取消,只会保留最后一次的 N 执行
# ignore-stdout 执行 'exec' 产生的 stdout 会被丢弃
# ignore-warn fileboy 自身的 warn 信息会被丢弃
# ignore-info fileboy 自身的 info 信息会被丢弃
# ignore-exec-error 执行 'exec' 出错仍继续执行下面的命令而不退出
instruction:
#- should-finish
#- exec-when-start
notifier:
# file changes send requests to the URL (POST JSON text data)
# the timing of triggering the request is consistent with executing the command command
@ -151,6 +138,22 @@ notifier:
# e.g: http://example.com/notifier/fileboy-listener
# no notice is enabled. Please leave it blank. ""
callUrl: ""
instruction:
# command behavior can be controlled by special command options. there can be multiple instructions
# options:
# exec-when-start when fileboy is ready to start, execute the command defined by 'exec' once automatically
# should-finish when the execution of 'exec' is triggered (C), if the last command (L) does not exit (still executing),
# it will wait for L to exit (instead of forcing kill), and the execution of this command will not start until L has an explicit exit code.
# when waiting for L to exit, and a new event triggers command execution (n), C execution is cancelled, and only the last N execution is retained
# ignore-stdout stdout generated by executing 'exec' will be discarded
# ignore-warn the warn information of fileboy itself will be discarded
# ignore-info the info information of fileboy itself will be discarded
# ignore-exec-error error executing 'exec' continue to execute the following command without exiting
#- should-finish
#- exec-when-start
- ignore-warn
```
### CONTRIBUTOR

View File

@ -73,13 +73,13 @@ func parseConfig() {
cfg.Monitor.IncludeDirsMap = map[string]bool{}
cfg.Monitor.ExceptDirsMap = map[string]bool{}
cfg.Monitor.IncludeDirsRec = map[string]bool{}
cfg.Command.InstructionMap = map[string]bool{}
cfg.InstructionMap = map[string]bool{}
// convert to map
for _, v := range cfg.Monitor.Types {
cfg.Monitor.TypesMap[v] = true
}
for _, v := range cfg.Command.Instruction {
cfg.Command.InstructionMap[v] = true
for _, v := range cfg.Instruction {
cfg.InstructionMap[v] = true
}
log.Printf("%+v", cfg)
}

View File

@ -18,14 +18,14 @@ type FileGirl struct {
IncludeDirsRec map[string]bool `yaml:"-"`
}
Command struct {
Instruction []string `yaml:"instruction"`
Exec []string `yaml:"exec"`
DelayMillSecond int `yaml:"delayMillSecond"`
// convert to
InstructionMap map[string]bool `yaml:"-"`
}
Notifier struct {
CallUrl string `yaml:"callUrl"`
}
Instruction []string `yaml:"instruction"`
// convert to
InstructionMap map[string]bool `yaml:"-"`
}

29
raw.go
View File

@ -69,19 +69,6 @@ command:
# 0
delayMillSecond: 2000
#
# command
# exec-when-start fileboy 'exec'
# should-finish 'exec' (C)(L)退 L 退 exit code
# L 退(N) C N
# ignore-stdout 'exec' stdout
# ignore-warn fileboy warn
# ignore-info fileboy info
# ignore-exec-error 'exec' 退
instruction:
#- should-finish
#- exec-when-start
#
notifier:
# url POST json
@ -94,6 +81,22 @@ notifier:
# : http://example.com/notifier/fileboy-listener
# ""
callUrl: ""
#
instruction:
# command
#
# exec-when-start fileboy 'exec'
# should-finish 'exec' (C)(L)退 L 退 kill L exit code
# L 退(N) C N
# ignore-stdout 'exec' stdout
# ignore-warn fileboy warn
# ignore-info fileboy info
# ignore-exec-error 'exec' 退
#- should-finish
#- exec-when-start
- ignore-warn
`
var firstRunHelp = ` fileboy ?

View File

@ -14,7 +14,7 @@ func keyInMonitorTypesMap(k string, cfg *FileGirl) bool {
}
func keyInInstruction(k string) bool {
_, ok := cfg.Command.InstructionMap[k]
_, ok := cfg.InstructionMap[k]
return ok
}