-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dapr component config for cron binding.
wip azure schedules. set minimum replicas of container apps that contain schedules to at least 1.
- Loading branch information
Showing
5 changed files
with
142 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package schedule | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/nitrictech/nitric/cloud/azure/deploy/exec" | ||
"github.com/pkg/errors" | ||
"github.com/pulumi/pulumi-azure-native-sdk/app" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
type ScheduleArgs struct { | ||
ResourceGroupName pulumi.StringInput | ||
Target *exec.ContainerApp | ||
Environment *app.ManagedEnvironment | ||
Cron string | ||
} | ||
|
||
type Schedule struct { | ||
pulumi.ResourceState | ||
|
||
Name string | ||
Component *app.DaprComponent | ||
} | ||
|
||
func NewDaprCronBindingSchedule(ctx *pulumi.Context, name string, args *ScheduleArgs, opts ...pulumi.ResourceOption) (*Schedule, error) { | ||
res := &Schedule{ | ||
Name: name, | ||
} | ||
normalizedName := strings.ToLower(strings.ReplaceAll(name, " ", "-")) | ||
err := ctx.RegisterComponentResource("nitric:func:ContainerApp", name, res, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res.Component, err = app.NewDaprComponent(ctx, normalizedName, &app.DaprComponentArgs{ | ||
ResourceGroupName: args.ResourceGroupName, | ||
EnvironmentName: args.Environment.Name, | ||
ComponentName: pulumi.String(strings.ReplaceAll(strings.ToLower(name), " ", "-")), | ||
ComponentType: pulumi.String("bindings.cron"), | ||
Version: pulumi.String("v1"), | ||
Metadata: app.DaprMetadataArray{ | ||
app.DaprMetadataArgs{ | ||
Name: pulumi.String("schedule"), | ||
Value: pulumi.String(args.Cron), | ||
}, | ||
// TODO: Validate that the route metadata will override the component name for routing | ||
app.DaprMetadataArgs{ | ||
Name: pulumi.String("route"), | ||
Value: pulumi.Sprintf("/x-nitric-schedule/%s", strings.ReplaceAll(strings.ToLower(name), " ", "-")), | ||
}, | ||
}, | ||
Scopes: pulumi.StringArray{ | ||
// Limit the scope to the target container app | ||
args.Target.App.Configuration.Dapr().AppId().Elem(), | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return nil, errors.WithMessage(err, "could not create DaprComponent for app") | ||
} | ||
|
||
return res, nil | ||
} |
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
Oops, something went wrong.