Skip to content

Commit

Permalink
added job to discard errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Apr 4, 2022
1 parent 2c15d5f commit a5190ca
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -107,6 +107,8 @@ func Get(t string) Job {
return checkJob
case "loop":
return loopJob
case "discard-error":
return discardErrorJob
case "encrypted":
return encryptedJob
default:
Expand Down
28 changes: 28 additions & 0 deletions src/job/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ func checkJob(ctx context.Context, logger *zap.Logger, _ *GlobalConfig, args con
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
) {
var jobConfig struct {
BasicJobConfig

Job config.Config
}

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

job := Get(jobConfig.Job.Type)
if job == nil {
logger.Debug("unknown job, discarding", zap.String("job", jobConfig.Job.Type))

return nil, nil
}

data, err = job(ctx, logger, globalConfig, jobConfig.Job.Args)
if err != nil {
logger.Debug("discarded error", zap.Error(err))
}

return data, nil
}

func loopJob(ctx context.Context, logger *zap.Logger, globalConfig *GlobalConfig, args config.Args) (data any, err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
Expand Down

0 comments on commit a5190ca

Please sign in to comment.