Skip to content

Commit 6947ba3

Browse files
committed
update update
1 parent 8db6312 commit 6947ba3

File tree

9 files changed

+56
-24
lines changed

9 files changed

+56
-24
lines changed

internal/worker/runner/exec/exec_other.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func (c *SCmd) transform(line string) string {
8080
return line
8181
}
8282

83-
func (c *SCmd) Run(ctx context.Context) (code int64, err error) {
83+
func (c *SCmd) Run(ctx context.Context) (exit int64, err error) {
8484
defer func() {
8585
c.cancel()
8686
if _r := recover(); _r != nil {
8787
err = fmt.Errorf("panic during execution %v", _r)
88-
code = common.CodeSystemErr
88+
exit = common.CodeSystemErr
8989
stack := debug.Stack()
9090
if _err, ok := _r.(error); ok && strings.Contains(_err.Error(), context.Canceled.Error()) {
91-
code = common.CodeKilled
91+
exit = common.CodeKilled
9292
err = common.ErrManual
9393
}
9494
c.storage.Log().Write(err.Error(), string(stack))
@@ -138,14 +138,14 @@ func (c *SCmd) Run(ctx context.Context) (code int64, err error) {
138138
go c.writeKeepAlive(ppty)
139139
err = cmd.Run()
140140
if cmd.ProcessState != nil {
141-
code = int64(cmd.ProcessState.ExitCode())
141+
exit = int64(cmd.ProcessState.ExitCode())
142142
if cmd.ProcessState.Pid() != 0 {
143143
_ = syscall.Kill(-cmd.ProcessState.Pid(), syscall.SIGKILL)
144144
c.reaper(cmd.ProcessState.Pid())
145145
}
146146
}
147-
if err != nil && code == 0 {
148-
code = common.CodeFailed
147+
if err != nil && exit == 0 {
148+
exit = common.CodeFailed
149149
}
150150
writer.AutoStop = true
151151
if _, _err := tty.Write([]byte("\x04")); _err != nil {
@@ -157,10 +157,10 @@ func (c *SCmd) Run(ctx context.Context) (code int64, err error) {
157157
switch {
158158
case errors.Is(context.Cause(c.ctx), common.ErrTimeOut):
159159
err = common.ErrTimeOut
160-
code = common.CodeTimeout
160+
exit = common.CodeTimeout
161161
default:
162162
err = common.ErrManual
163-
code = common.CodeKilled
163+
exit = common.CodeKilled
164164
}
165165
}
166166
return

internal/worker/runner/exec/exec_windows.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func (c *SCmd) selfCmd() *exec.Cmd {
5151
return cmd
5252
}
5353

54-
func (c *SCmd) Run(ctx context.Context) (code int64, err error) {
54+
func (c *SCmd) Run(ctx context.Context) (exit int64, err error) {
5555
defer func() {
5656
c.cancel()
5757
if _r := recover(); _r != nil {
5858
err = fmt.Errorf("panic during execution %v", _r)
59-
code = common.CodeSystemErr
59+
exit = common.CodeSystemErr
6060
stack := debug.Stack()
6161
if _err, ok := _r.(error); ok && strings.Contains(_err.Error(), context.Canceled.Error()) {
62-
code = common.CodeKilled
62+
exit = common.CodeKilled
6363
err = common.ErrManual
6464
}
6565
c.storage.Log().Write(err.Error(), string(stack))
@@ -85,22 +85,22 @@ func (c *SCmd) Run(ctx context.Context) (code int64, err error) {
8585
go c.copyOutput(reader)
8686
err = cmd.Run()
8787
if cmd.ProcessState != nil {
88-
code = int64(cmd.ProcessState.ExitCode())
88+
exit = int64(cmd.ProcessState.ExitCode())
8989
if cmd.ProcessState.Pid() != 0 {
9090
_ = c.kill(cmd.ProcessState.Pid())
9191
}
9292
}
93-
if err != nil && code == 0 {
94-
code = common.CodeFailed
93+
if err != nil && exit == 0 {
94+
exit = common.CodeFailed
9595
}
9696
if c.ctx.Err() != nil {
9797
switch {
9898
case errors.Is(context.Cause(c.ctx), common.ErrTimeOut):
9999
err = common.ErrTimeOut
100-
code = common.CodeTimeout
100+
exit = common.CodeTimeout
101101
default:
102102
err = common.ErrManual
103-
code = common.CodeKilled
103+
exit = common.CodeKilled
104104
}
105105
}
106106
return

internal/worker/runner/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import (
55
)
66

77
type IRunner interface {
8-
Run(ctx context.Context) (code int64, err error)
8+
Run(ctx context.Context) (exit int64, err error)
99
Clear() error
1010
}

internal/worker/runner/k8s/kubernetes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ func (k *SKubectl) init() (err error) {
111111
return
112112
}
113113

114-
func (k *SKubectl) Run(ctx context.Context) (code int64, err error) {
114+
func (k *SKubectl) Run(ctx context.Context) (exit int64, err error) {
115115
defer func() {
116116
r := recover()
117117
if r != nil {
118118
logx.Errorln(string(debug.Stack()), r)
119119
err = fmt.Errorf("panic: %s", r)
120-
code = common.CodeSystemErr
120+
exit = common.CodeSystemErr
121121
}
122122
}()
123123
timeout, err := k.storage.Timeout()

internal/worker/runner/mkdir/mkdir.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func New(
3030
}, nil
3131
}
3232

33-
func (m *SMkdir) Run(ctx context.Context) (code int64, err error) {
33+
func (m *SMkdir) Run(ctx context.Context) (exit int64, err error) {
3434
content, err := m.storage.Content()
3535
if err != nil {
3636
return common.CodeSystemErr, err

internal/worker/runner/runner.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/xmapst/AutoExecFlow/internal/worker/runner/k8s"
99
"github.com/xmapst/AutoExecFlow/internal/worker/runner/mkdir"
1010
"github.com/xmapst/AutoExecFlow/internal/worker/runner/touch"
11+
"github.com/xmapst/AutoExecFlow/internal/worker/runner/wasm"
1112
"github.com/xmapst/AutoExecFlow/internal/worker/runner/yaegi"
1213
)
1314

@@ -28,6 +29,8 @@ func New(
2829
return touch.New(storage, workspace)
2930
case strings.EqualFold(commandType, "yaegi"):
3031
return yaegi.New(storage, workspace)
32+
case strings.EqualFold(commandType, "wasm"):
33+
return wasm.New(storage, workspace)
3134
default:
3235
return exec.New(storage, commandType, workspace, scriptDir)
3336
}

internal/worker/runner/touch/touch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func New(
3232
}, nil
3333
}
3434

35-
func (t *STouch) Run(ctx context.Context) (code int64, err error) {
35+
func (t *STouch) Run(ctx context.Context) (exit int64, err error) {
3636
content, err := t.storage.Content()
3737
if err != nil {
3838
return common.CodeSystemErr, err

internal/worker/runner/wasm/wasm.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package wasm
2+
3+
import (
4+
"context"
5+
6+
"github.com/xmapst/AutoExecFlow/internal/storage"
7+
)
8+
9+
type SWasm struct {
10+
storage storage.IStep
11+
workspace string
12+
}
13+
14+
func New(storage storage.IStep, workspace string) (*SWasm, error) {
15+
return &SWasm{
16+
storage: storage,
17+
workspace: workspace,
18+
}, nil
19+
}
20+
21+
func (w *SWasm) Run(ctx context.Context) (exit int64, err error) {
22+
//TODO implement me
23+
panic("implement me")
24+
}
25+
26+
func (w *SWasm) Clear() error {
27+
//TODO implement me
28+
panic("implement me")
29+
}

internal/worker/runner/yaegi/yaegi.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func New(storage storage.IStep, workspace string) (*SYaegi, error) {
2929
}, nil
3030
}
3131

32-
func (y *SYaegi) Run(ctx context.Context) (code int64, err error) {
32+
func (y *SYaegi) Run(ctx context.Context) (exit int64, err error) {
3333
defer func() {
3434
if _r := recover(); _r != nil {
3535
err = fmt.Errorf("panic during execution %v", _r)
36-
code = common.CodeSystemErr
36+
exit = common.CodeSystemErr
3737
stack := debug.Stack()
3838
if _err, ok := _r.(error); ok && strings.Contains(_err.Error(), context.Canceled.Error()) {
39-
code = common.CodeKilled
39+
exit = common.CodeKilled
4040
err = common.ErrManual
4141
}
4242
y.storage.Log().Write(err.Error(), string(stack))

0 commit comments

Comments
 (0)