-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tasks): add a tasks.lastSuccess function (#3144)
This patch adds a `lastSuccess` function that can be used to return the last successful time a task ran. This patch only provides the interface, and will error if called directly, and will be overridden/implemented on the server first. Fixes #3080
- Loading branch information
Showing
7 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// DO NOT EDIT: This file is autogenerated via the builtin command. | ||
|
||
package tasks | ||
|
||
import ( | ||
ast "github.com/influxdata/flux/ast" | ||
parser "github.com/influxdata/flux/internal/parser" | ||
runtime "github.com/influxdata/flux/runtime" | ||
) | ||
|
||
func init() { | ||
runtime.RegisterPackage(pkgAST) | ||
} | ||
|
||
var pkgAST = &ast.Package{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: nil, | ||
}, | ||
Files: []*ast.File{&ast.File{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 20, | ||
Line: 10, | ||
}, | ||
File: "tasks.flux", | ||
Source: "package tasks\n\noption lastSuccessTime = 0000-01-01T00:00:00Z\n\n// This is currently a noop, as its implementation is meant to be\n// overridden elsewhere.\n// As this function currently only returns an unimplemented error, and \n// flux has no support for doing this natively, this function is a builtin.\n// When fully implemented, it should be able to be implemented in pure flux.\nbuiltin lastSuccess", | ||
Start: ast.Position{ | ||
Column: 1, | ||
Line: 1, | ||
}, | ||
}, | ||
}, | ||
Body: []ast.Statement{&ast.OptionStatement{ | ||
Assignment: &ast.VariableAssignment{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 46, | ||
Line: 3, | ||
}, | ||
File: "tasks.flux", | ||
Source: "lastSuccessTime = 0000-01-01T00:00:00Z", | ||
Start: ast.Position{ | ||
Column: 8, | ||
Line: 3, | ||
}, | ||
}, | ||
}, | ||
ID: &ast.Identifier{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 23, | ||
Line: 3, | ||
}, | ||
File: "tasks.flux", | ||
Source: "lastSuccessTime", | ||
Start: ast.Position{ | ||
Column: 8, | ||
Line: 3, | ||
}, | ||
}, | ||
}, | ||
Name: "lastSuccessTime", | ||
}, | ||
Init: &ast.DateTimeLiteral{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 46, | ||
Line: 3, | ||
}, | ||
File: "tasks.flux", | ||
Source: "0000-01-01T00:00:00Z", | ||
Start: ast.Position{ | ||
Column: 26, | ||
Line: 3, | ||
}, | ||
}, | ||
}, | ||
Value: parser.MustParseTime("0000-01-01T00:00:00Z"), | ||
}, | ||
}, | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 46, | ||
Line: 3, | ||
}, | ||
File: "tasks.flux", | ||
Source: "option lastSuccessTime = 0000-01-01T00:00:00Z", | ||
Start: ast.Position{ | ||
Column: 1, | ||
Line: 3, | ||
}, | ||
}, | ||
}, | ||
}, &ast.BuiltinStatement{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 20, | ||
Line: 10, | ||
}, | ||
File: "tasks.flux", | ||
Source: "builtin lastSuccess", | ||
Start: ast.Position{ | ||
Column: 1, | ||
Line: 10, | ||
}, | ||
}, | ||
}, | ||
ID: &ast.Identifier{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 20, | ||
Line: 10, | ||
}, | ||
File: "tasks.flux", | ||
Source: "lastSuccess", | ||
Start: ast.Position{ | ||
Column: 9, | ||
Line: 10, | ||
}, | ||
}, | ||
}, | ||
Name: "lastSuccess", | ||
}, | ||
}}, | ||
Imports: nil, | ||
Metadata: "parser-type=rust", | ||
Name: "tasks.flux", | ||
Package: &ast.PackageClause{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 14, | ||
Line: 1, | ||
}, | ||
File: "tasks.flux", | ||
Source: "package tasks", | ||
Start: ast.Position{ | ||
Column: 1, | ||
Line: 1, | ||
}, | ||
}, | ||
}, | ||
Name: &ast.Identifier{ | ||
BaseNode: ast.BaseNode{ | ||
Errors: nil, | ||
Loc: &ast.SourceLocation{ | ||
End: ast.Position{ | ||
Column: 14, | ||
Line: 1, | ||
}, | ||
File: "tasks.flux", | ||
Source: "tasks", | ||
Start: ast.Position{ | ||
Column: 9, | ||
Line: 1, | ||
}, | ||
}, | ||
}, | ||
Name: "tasks", | ||
}, | ||
}, | ||
}}, | ||
Package: "tasks", | ||
Path: "influxdata/influxdb/tasks", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package tasks_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/influxdata/flux" | ||
"github.com/influxdata/flux/codes" | ||
"github.com/influxdata/flux/dependencies/dependenciestest" | ||
"github.com/influxdata/flux/stdlib/influxdata/influxdb/tasks" | ||
"github.com/influxdata/flux/values" | ||
) | ||
|
||
func TestLastSuccess(t *testing.T) { | ||
t.Run("lastSuccess test", func(t *testing.T) { | ||
fluxArg := values.NewObjectWithValues(map[string]values.Value{"orTime": values.NewTime(100)}) | ||
|
||
_, got := tasks.LastSuccessFunction.Call(dependenciestest.Default().Inject(context.Background()), fluxArg) | ||
|
||
if got == nil { | ||
t.Fatal("lastSuccess should produce an error") | ||
} | ||
|
||
want := &flux.Error{ | ||
Code: codes.Unimplemented, | ||
Msg: "This function is not yet implemented.", | ||
} | ||
|
||
if !cmp.Equal(want, got) { | ||
t.Fatalf("unexpected result -want/+got\n\n%s\n\n", cmp.Diff(want, got)) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tasks | ||
|
||
option lastSuccessTime = 0000-01-01T00:00:00Z | ||
|
||
// This is currently a noop, as its implementation is meant to be | ||
// overridden elsewhere. | ||
// As this function currently only returns an unimplemented error, and | ||
// flux has no support for doing this natively, this function is a builtin. | ||
// When fully implemented, it should be able to be implemented in pure flux. | ||
builtin lastSuccess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tasks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/influxdata/flux/codes" | ||
"github.com/influxdata/flux/internal/errors" | ||
"github.com/influxdata/flux/interpreter" | ||
"github.com/influxdata/flux/runtime" | ||
"github.com/influxdata/flux/values" | ||
) | ||
|
||
const LastSuccessKind = "lastSuccess" | ||
|
||
func init() { | ||
runtime.RegisterPackageValue("influxdata/influxdb/tasks", LastSuccessKind, LastSuccessFunction) | ||
} | ||
|
||
// LastSuccessFunction is a function that calls LastSuccess. | ||
var LastSuccessFunction = makeLastSuccessFunc() | ||
|
||
func makeLastSuccessFunc() values.Function { | ||
sig := runtime.MustLookupBuiltinType("influxdata/influxdb/tasks", "lastSuccess") | ||
return values.NewFunction("lastSuccess", sig, LastSuccess, false) | ||
} | ||
|
||
// LastSuccess retrieves the last successful run of the task, or returns the value of the | ||
// orTime parameter if the task has never successfully run. | ||
func LastSuccess(ctx context.Context, args values.Object) (values.Value, error) { | ||
fargs := interpreter.NewArguments(args) | ||
_, err := fargs.GetRequired("orTime") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, errors.Newf(codes.Unimplemented, "This function is not yet implemented.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters