Skip to content

Commit

Permalink
add simple timeout job
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Apr 4, 2022
1 parent a5190ca commit ccecdf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/job/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func Get(t string) Job {
return setVarJob
case "check":
return checkJob
case "timeout":
return timeoutJob
case "loop":
return loopJob
case "discard-error":
Expand Down
15 changes: 15 additions & 0 deletions src/job/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"encoding/base64"
"fmt"
"time"

"github.com/mitchellh/mapstructure"
"go.uber.org/zap"
Expand Down Expand Up @@ -81,6 +82,20 @@ func checkJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args con
return nil, nil
}

func timeoutJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args config.Args) (data any, err error) {
var jobConfig struct {
Value time.Duration
}

if err := utils.Decode(args, &jobConfig); err != nil {
return nil, fmt.Errorf("error parsing job config: %w", err)
}

time.Sleep(jobConfig.Value)

return nil, nil
}

func discardErrorJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (
data any, err error, //nolint:unparam // data is here to match Job
) {
Expand Down

0 comments on commit ccecdf8

Please sign in to comment.