diff --git a/go.mod b/go.mod index 2a3d0b2..ca8485c 100644 --- a/go.mod +++ b/go.mod @@ -9,12 +9,12 @@ require ( github.com/felixge/httpsnoop v1.0.4 github.com/go-courier/logr v0.3.0 github.com/go-json-experiment/json v0.0.0-20240815175050-ebd3a8989ca1 - github.com/innoai-tech/openapi-playground v0.0.0-20240920071141-a9f087bad00f - github.com/octohelm/courier v0.0.0-20241016053631-360e3af3e736 + github.com/innoai-tech/openapi-playground v0.0.0-20241021014502-87119c104e6a + github.com/octohelm/courier v0.0.0-20241019060647-30c761fc7341 github.com/octohelm/gengo v0.0.0-20241014043309-2344b8632080 github.com/octohelm/storage v0.0.0-20241014040055-4f454a8d6947 github.com/octohelm/x v0.0.0-20241011014327-0fcf864c84d6 - github.com/prometheus/client_golang v1.20.4 + github.com/prometheus/client_golang v1.20.5 github.com/prometheus/prometheus v0.54.1 github.com/robfig/cron/v3 v3.0.1 github.com/spf13/cobra v1.8.1 @@ -68,8 +68,8 @@ require ( golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect golang.org/x/tools v0.26.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect google.golang.org/grpc v1.67.1 // indirect google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 86fb5ca..5121b94 100644 --- a/go.sum +++ b/go.sum @@ -72,12 +72,15 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248= github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/innoai-tech/openapi-playground v0.0.0-20240920071141-a9f087bad00f h1:7GQQEvaFt+npnJH08AMm6A2UecFhzKI51lsBOUKgXgY= github.com/innoai-tech/openapi-playground v0.0.0-20240920071141-a9f087bad00f/go.mod h1:XF6gAVE9R8xSKHWbG0TtH/7RbWrTh16PH23eGZk69po= +github.com/innoai-tech/openapi-playground v0.0.0-20241021014502-87119c104e6a h1:7KOpMaXUDnURdycHLmgQoyjSPj4gaYrpHbb2oQ877b4= +github.com/innoai-tech/openapi-playground v0.0.0-20241021014502-87119c104e6a/go.mod h1:XF6gAVE9R8xSKHWbG0TtH/7RbWrTh16PH23eGZk69po= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= @@ -117,6 +120,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/octohelm/courier v0.0.0-20241016053631-360e3af3e736 h1:uuFOBTZiJNThNtdbrP2SJpCk+syQaN1RQcxYHoXFH3A= github.com/octohelm/courier v0.0.0-20241016053631-360e3af3e736/go.mod h1:uHccmYdw4rrly3faZQHLkZGCDYjj3zuwjKrUYo4QiXo= +github.com/octohelm/courier v0.0.0-20241019060647-30c761fc7341 h1:BFjtJMZlorxbKulNGosL87HS2m7RKwz05pCgzlPT3yQ= +github.com/octohelm/courier v0.0.0-20241019060647-30c761fc7341/go.mod h1:uHccmYdw4rrly3faZQHLkZGCDYjj3zuwjKrUYo4QiXo= github.com/octohelm/gengo v0.0.0-20241014043309-2344b8632080 h1:JydhpFfiuBsIXWs4f3GQJDpCmG5LFKgzB7CFkRGWs3s= github.com/octohelm/gengo v0.0.0-20241014043309-2344b8632080/go.mod h1:7bkbdNmnQEmnVbvdSJdRwvGmm2/3KgvxXSDi/nXCOk8= github.com/octohelm/storage v0.0.0-20241014040055-4f454a8d6947 h1:NrKmBgKHtl0FK3RZMZ9x9Epm6ZYnd97SOhjne46pfQY= @@ -141,6 +146,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= @@ -250,8 +257,12 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 h1:T6rh4haD3GVYsgEfWExoCZA2o2FmbNyKpTuAxbEFPTg= google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:wp2WsuBYj6j8wUdo3ToZsdxxixbvQNAHqVJrTgi5E5M= +google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 h1:fVoAXEKA4+yufmbdVYv+SE73+cPZbbbe8paLsHfkK+U= +google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53/go.mod h1:riSXTwQ4+nqmPGtobMFyW5FqVAmIs0St6VPp4Ug7CE4= google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc= google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= diff --git a/pkg/configuration/context.go b/pkg/configuration/context.go index 3d639cd..963308a 100644 --- a/pkg/configuration/context.go +++ b/pkg/configuration/context.go @@ -70,3 +70,7 @@ type injectContextFunc[T any] struct { func (f *injectContextFunc[T]) InjectContext(ctx context.Context) context.Context { return f.inject(ctx, f.input) } + +func Background(ctx context.Context) context.Context { + return ContextInjectorFromContext(ctx).InjectContext(context.Background()) +} diff --git a/pkg/cron/job.go b/pkg/cron/job.go index 840f835..f4657bd 100644 --- a/pkg/cron/job.go +++ b/pkg/cron/job.go @@ -12,6 +12,30 @@ import ( "github.com/robfig/cron/v3" ) +type Schedule struct { + // cron job 配置 + // 支持 标准格式 + // 也支持 @every {duration} 等语义化格式 + Cron string `flag:",omitempty"` + + schedule cron.Schedule +} + +func (s Schedule) Schedule() cron.Schedule { + return s.schedule +} + +func (j *Schedule) Init(ctx context.Context) error { + if j.schedule == nil { + schedule, err := cron.ParseStandard(j.Cron) + if err != nil { + return fmt.Errorf("parse cron failed: %s: %w", j.Cron, err) + } + j.schedule = schedule + } + return nil +} + type IntervalSchedule struct { Interval time.Duration } diff --git a/pkg/cron/zz_generated.runtimedoc.go b/pkg/cron/zz_generated.runtimedoc.go index ae1bb14..d558079 100644 --- a/pkg/cron/zz_generated.runtimedoc.go +++ b/pkg/cron/zz_generated.runtimedoc.go @@ -43,3 +43,20 @@ func (v Job) RuntimeDoc(names ...string) ([]string, bool) { } return []string{}, true } + +func (v Schedule) RuntimeDoc(names ...string) ([]string, bool) { + if len(names) > 0 { + switch names[0] { + case "Cron": + return []string{ + "cron job 配置", + "支持 标准格式", + "也支持 @every {duration} 等语义化格式", + }, true + + } + + return nil, false + } + return []string{}, true +}