Skip to content

Commit

Permalink
INN-2827 Add ability to specify multiple triggers (#35)
Browse files Browse the repository at this point in the history
* Upstream OSS to include `Triggerable`

* Add ability to provide multiple triggers when creating a function
  • Loading branch information
jpwilliams authored Mar 11, 2024
1 parent e835c79 commit 7b67583
Show file tree
Hide file tree
Showing 51 changed files with 1,346 additions and 2,652 deletions.
8 changes: 4 additions & 4 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r RateLimit) Convert() *inngest.RateLimit {
// )
func CreateFunction[T any](
fc FunctionOpts,
trigger inngest.Trigger,
trigger inngest.Triggerable,
f SDKFunction[T],
) ServableFunction {
// Validate that the input type is a concrete type, and not an interface.
Expand Down Expand Up @@ -170,7 +170,7 @@ type ServableFunction interface {
Config() FunctionOpts

// Trigger returns the event name or schedule that triggers the function.
Trigger() inngest.Trigger
Trigger() inngest.Triggerable

// ZeroEvent returns the zero event type to marshal the event into, given an
// event name.
Expand Down Expand Up @@ -200,7 +200,7 @@ type InputCtx struct {

type servableFunc struct {
fc FunctionOpts
trigger inngest.Trigger
trigger inngest.Triggerable
f any
}

Expand All @@ -219,7 +219,7 @@ func (s servableFunc) Name() string {
return s.fc.Name
}

func (s servableFunc) Trigger() inngest.Trigger {
func (s servableFunc) Trigger() inngest.Triggerable {
return s.trigger
}

Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible => gith
require (
github.com/gosimple/slug v1.12.0
github.com/gowebpki/jcs v1.0.0
github.com/inngest/inngest v0.24.4-0.20240125144251-d920c39952bc
github.com/inngest/inngest v0.26.3-0.20240229121853-bf40aa29d3af
github.com/stretchr/testify v1.8.4
github.com/xhit/go-str2duration/v2 v2.1.0
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
Expand All @@ -22,14 +22,14 @@ require (
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/cel-go v0.18.2 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.10.0 // indirect
github.com/hashicorp/terraform v0.15.3 // indirect
github.com/inngest/expr v0.0.0-20240109020554-19e459e1e8d4 // indirect
github.com/inngest/expr v0.0.0-20240201152704-a643bc6ace48 // indirect
github.com/karlseguin/ccache/v2 v2.0.8 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -39,7 +39,6 @@ require (
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/plar/go-adaptive-radix-tree v1.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/zerolog v1.26.1 // indirect
Expand Down
19 changes: 6 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
Expand Down Expand Up @@ -303,10 +303,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inngest/expr v0.0.0-20240109020554-19e459e1e8d4 h1:BQBcRZSjbasKnIfY+6bcILvhjHbg1xAG0HCbi7/K6Xw=
github.com/inngest/expr v0.0.0-20240109020554-19e459e1e8d4/go.mod h1:DTBHXcOdO3hWDTUylFeICDSgd5RbaG1xEnacfiN8V4M=
github.com/inngest/inngest v0.24.4-0.20240125144251-d920c39952bc h1:kMP6jNdWEHVzqlZStpOuVJuxkuWFUgY7mPyylbV6yEk=
github.com/inngest/inngest v0.24.4-0.20240125144251-d920c39952bc/go.mod h1:zUokJRMslW58IiYwlSMRuh0lKZ00MI6rdjo/ST40W8c=
github.com/inngest/expr v0.0.0-20240201152704-a643bc6ace48 h1:32YlbLIeO8HOMzYF3DfRLNX8hKeDb8omccWf03PHyh4=
github.com/inngest/expr v0.0.0-20240201152704-a643bc6ace48/go.mod h1:Evn0nMuDe2NghjynoNzNwwc8ONXuFVzVr1H93tCwPyE=
github.com/inngest/inngest v0.26.3-0.20240229121853-bf40aa29d3af h1:x06KIKaXVJeKR5Q5sDLICo0FRMRpHcM3gpfMKL5uyso=
github.com/inngest/inngest v0.26.3-0.20240229121853-bf40aa29d3af/go.mod h1:AACs06uRhKFHxcC2jHIbi5SeixRKE0BBLdTv2UjB86Q=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
Expand Down Expand Up @@ -421,8 +421,6 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/plar/go-adaptive-radix-tree v1.0.5 h1:rHR89qy/6c24TBAHullFMrJsU9hGlKmPibdBGU6/gbM=
github.com/plar/go-adaptive-radix-tree v1.0.5/go.mod h1:15VOUO7R9MhJL8HOJdpydR0rvanrtRE6fA6XSa/tqWE=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -469,18 +467,13 @@ github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ai
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
Expand Down
26 changes: 16 additions & 10 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (h *handler) register(w http.ResponseWriter, r *http.Request) error {
Slug: h.appName + "-" + fn.Slug(),
Idempotency: c.Idempotency,
Priority: fn.Config().Priority,
Triggers: []inngest.Trigger{{}},
Triggers: inngest.MultipleTriggers{},
RateLimit: fn.Config().GetRateLimit(),
Cancel: fn.Config().Cancel,
Steps: map[string]sdk.SDKStep{
Expand Down Expand Up @@ -325,15 +325,21 @@ func (h *handler) register(w http.ResponseWriter, r *http.Request) error {
f.Concurrency = &inngest.ConcurrencyLimits{Limits: c.Concurrency}
}

trigger := fn.Trigger()
if trigger.EventTrigger != nil {
f.Triggers[0].EventTrigger = &inngest.EventTrigger{
Event: trigger.Event,
Expression: trigger.Expression,
}
} else {
f.Triggers[0].CronTrigger = &inngest.CronTrigger{
Cron: trigger.Cron,
triggers := fn.Trigger().Triggers()
for _, trigger := range triggers {
if trigger.EventTrigger != nil {
f.Triggers = append(f.Triggers, inngest.Trigger{
EventTrigger: &inngest.EventTrigger{
Event: trigger.Event,
Expression: trigger.Expression,
},
})
} else {
f.Triggers = append(f.Triggers, inngest.Trigger{
CronTrigger: &inngest.CronTrigger{
Cron: trigger.Cron,
},
})
}
}

Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/google/uuid/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/google/uuid/hash.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions vendor/github.com/google/uuid/time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions vendor/github.com/google/uuid/uuid.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions vendor/github.com/google/uuid/version6.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b67583

Please sign in to comment.