feat(process): forward task run options
This commit is contained in:
parent
1b7431e3a0
commit
252f68db64
3 changed files with 36 additions and 4 deletions
10
actions.go
10
actions.go
|
|
@ -11,6 +11,16 @@ type TaskProcessRun struct {
|
|||
Args []string
|
||||
Dir string
|
||||
Env []string
|
||||
// DisableCapture skips buffering process output before returning it.
|
||||
DisableCapture bool
|
||||
// Detach runs the command in its own process group.
|
||||
Detach bool
|
||||
// Timeout bounds the execution duration.
|
||||
Timeout time.Duration
|
||||
// GracePeriod controls SIGTERM-to-SIGKILL escalation.
|
||||
GracePeriod time.Duration
|
||||
// KillGroup terminates the entire process group instead of only the leader.
|
||||
KillGroup bool
|
||||
}
|
||||
|
||||
// ActionProcessStarted is broadcast when a process begins execution.
|
||||
|
|
|
|||
13
service.go
13
service.go
|
|
@ -417,10 +417,15 @@ func (s *Service) handleTask(c *core.Core, task core.Task) core.Result {
|
|||
switch m := task.(type) {
|
||||
case TaskProcessRun:
|
||||
output, err := s.RunWithOptions(c.Context(), RunOptions{
|
||||
Command: m.Command,
|
||||
Args: m.Args,
|
||||
Dir: m.Dir,
|
||||
Env: m.Env,
|
||||
Command: m.Command,
|
||||
Args: m.Args,
|
||||
Dir: m.Dir,
|
||||
Env: m.Env,
|
||||
DisableCapture: m.DisableCapture,
|
||||
Detach: m.Detach,
|
||||
Timeout: m.Timeout,
|
||||
GracePeriod: m.GracePeriod,
|
||||
KillGroup: m.KillGroup,
|
||||
})
|
||||
if err != nil {
|
||||
return core.Result{Value: err, OK: false}
|
||||
|
|
|
|||
|
|
@ -500,6 +500,23 @@ func TestService_OnStartup(t *testing.T) {
|
|||
require.True(t, result.OK)
|
||||
assert.Contains(t, result.Value.(string), "action-run")
|
||||
})
|
||||
|
||||
t.Run("forwards task execution options", func(t *testing.T) {
|
||||
svc, c := newTestService(t)
|
||||
|
||||
err := svc.OnStartup(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
result := c.PERFORM(TaskProcessRun{
|
||||
Command: "sleep",
|
||||
Args: []string{"60"},
|
||||
Timeout: 100 * time.Millisecond,
|
||||
GracePeriod: 50 * time.Millisecond,
|
||||
})
|
||||
|
||||
require.False(t, result.OK)
|
||||
assert.Nil(t, result.Value)
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_RunWithOptions(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue