-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
task.length.go
43 lines (33 loc) · 964 Bytes
/
task.length.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pipeline
import (
"context"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
"go.uber.org/multierr"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)
// Return types:
//
// *decimal.Decimal
type LengthTask struct {
BaseTask `mapstructure:",squash"`
Input string `json:"input"`
}
var _ Task = (*LengthTask)(nil)
func (t *LengthTask) Type() TaskType {
return TaskTypeLength
}
func (t *LengthTask) Run(_ context.Context, _ logger.Logger, vars Vars, inputs []Result) (result Result, runInfo RunInfo) {
_, err := CheckInputs(inputs, 0, 1, 0)
if err != nil {
return Result{Error: errors.Wrap(err, "task inputs")}, runInfo
}
var input BytesParam
err = multierr.Combine(
errors.Wrap(ResolveParam(&input, From(VarExpr(t.Input, vars), NonemptyString(t.Input), Input(inputs, 0))), "input"),
)
if err != nil {
return Result{Error: err}, runInfo
}
return Result{Value: decimal.NewFromInt(int64(len(input)))}, runInfo
}