-
Notifications
You must be signed in to change notification settings - Fork 209
Adds dapr scheduler.
#1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Adds dapr scheduler.
#1559
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bbfe027
Adds `dapr scheduler`
JoshVanL de38192
Fix unit tests
JoshVanL 768f237
Use correct latest version number for dapr e2e
JoshVanL 0d78d2a
Apply suggestion from @acroca
JoshVanL eeedd44
Apply suggestion from @acroca
JoshVanL f35cbee
Change name is reflect filter
JoshVanL afcfd29
Humanize last trigger time
JoshVanL 41d1c99
Review comments
JoshVanL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package scheduler | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/scheduler" | ||
| "github.com/dapr/kit/signals" | ||
| ) | ||
|
|
||
| var DeleteCmd = &cobra.Command{ | ||
| Use: "delete", | ||
| Aliases: []string{"d", "del"}, | ||
| Short: `Delete one of more jobs from scheduler. | ||
| Job names are formatted by their type, app ID, then identifier. | ||
| Actor reminders require the actor type, actor ID, then reminder name, separated by /. | ||
| Workflow reminders require the app ID, instance ID, then reminder name, separated by /. | ||
| Accepts multiple names. | ||
| `, | ||
| Args: cobra.MinimumNArgs(1), | ||
| Example: ` | ||
| dapr scheduler delete app/my-app-id/my-job-name | ||
| dapr scheduler delete actor/my-actor-type/my-actor-id/my-reminder-name | ||
| dapr scheduler delete workflow/my-app-id/my-instance-id/my-workflow-reminder-name | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := signals.Context() | ||
| opts := scheduler.DeleteOptions{ | ||
| SchedulerNamespace: schedulerNamespace, | ||
| KubernetesMode: kubernetesMode, | ||
| DaprNamespace: daprNamespace, | ||
| } | ||
|
|
||
| return scheduler.Delete(ctx, opts, args...) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| SchedulerCmd.AddCommand(DeleteCmd) | ||
| } |
This file contains hidden or 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,54 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package scheduler | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/scheduler" | ||
| "github.com/dapr/kit/signals" | ||
| ) | ||
|
|
||
| var DeleteAllCmd = &cobra.Command{ | ||
| Use: "delete-all", | ||
| Aliases: []string{"da", "delall"}, | ||
| Short: `Delete all scheduled jobs in the specified namespace of a particular filter. | ||
| Accepts a single key as an argument. Deletes all jobs which match the filter key. | ||
| `, | ||
| Args: cobra.ExactArgs(1), | ||
| Example: ` | ||
| dapr scheduler delete-all all | ||
| dapr scheduler delete-all app | ||
| dapr scheduler delete-all app/my-app-id | ||
| dapr scheduler delete-all actor/my-actor-type | ||
| dapr scheduler delete-all actor/my-actor-type/my-actor-id | ||
| dapr scheduler delete-all workflow | ||
| dapr scheduler delete-all workflow/my-app-id | ||
| dapr scheduler delete-all workflow/my-app-id/my-workflow-id | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := signals.Context() | ||
| opts := scheduler.DeleteOptions{ | ||
| SchedulerNamespace: schedulerNamespace, | ||
| KubernetesMode: kubernetesMode, | ||
| DaprNamespace: daprNamespace, | ||
| } | ||
|
|
||
| return scheduler.DeleteAll(ctx, opts, args[0]) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| SchedulerCmd.AddCommand(DeleteAllCmd) | ||
| } | ||
This file contains hidden or 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,61 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package scheduler | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/print" | ||
| "github.com/dapr/cli/pkg/scheduler" | ||
| "github.com/dapr/kit/signals" | ||
| ) | ||
|
|
||
| var ( | ||
| schedulerExportFile string | ||
| ) | ||
|
|
||
| var SchedulerExportCmd = &cobra.Command{ | ||
| Use: "export", | ||
| Short: "Export all jobs and actor reminders to a binary file, including the tracked count.", | ||
| Long: `Export jobs and actor reminders which are scheduled in Scheduler. | ||
| Can later be imported using 'dapr scheduler import'. | ||
| dapr scheduler export -o output.bin | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := signals.Context() | ||
|
|
||
| err := scheduler.Export(ctx, scheduler.ExportImportOptions{ | ||
| SchedulerNamespace: schedulerNamespace, | ||
| KubernetesMode: kubernetesMode, | ||
| TargetFile: schedulerExportFile, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| print.InfoStatusEvent(os.Stdout, "Export to '%s' complete.", schedulerExportFile) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| SchedulerExportCmd.Flags().MarkHidden("namespace") | ||
| SchedulerExportCmd.Flags().StringVarP(&schedulerExportFile, "output-file", "o", "", "Output binary file to export jobs and actor reminders to.") | ||
| SchedulerExportCmd.MarkFlagRequired("output-file") | ||
| SchedulerExportCmd.MarkFlagFilename("output-file") | ||
| SchedulerCmd.AddCommand(SchedulerExportCmd) | ||
| } |
This file contains hidden or 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,93 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package scheduler | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/gocarina/gocsv" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/scheduler" | ||
| "github.com/dapr/cli/utils" | ||
| "github.com/dapr/kit/signals" | ||
| ) | ||
|
|
||
| var ( | ||
| getOutputFormat *string | ||
| ) | ||
|
|
||
| var GetCmd = &cobra.Command{ | ||
| Use: "get", | ||
| Aliases: []string{"g", "ge"}, | ||
| Short: `Get a scheduled app job or actor reminder in Scheduler. | ||
| Job names are formatted by their type, app ID, then identifier. | ||
| Actor reminders require the actor type, actor ID, then reminder name, separated by /. | ||
| Workflow reminders require the app ID, instance ID, then reminder name, separated by /. | ||
| Activity reminders require the app ID, activity ID, separated by /. | ||
| Accepts multiple names. | ||
| `, | ||
| Args: cobra.MinimumNArgs(1), | ||
| Example: ` | ||
| dapr scheduler get app/my-app-id/my-job-name | ||
| dapr scheduler get actor/my-actor-type/my-actor-id/my-reminder-name | ||
| dapr scheduler get workflow/my-app-id/my-instance-id/my-workflow-reminder-name | ||
| dapr scheduler get activity/my-app-id/xyz::0::1 | ||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := signals.Context() | ||
| opts := scheduler.GetOptions{ | ||
| SchedulerNamespace: schedulerNamespace, | ||
| KubernetesMode: kubernetesMode, | ||
| DaprNamespace: daprNamespace, | ||
| } | ||
|
|
||
| var list any | ||
| var err error | ||
| if *getOutputFormat == outputFormatShort { | ||
| list, err = scheduler.Get(ctx, opts, args...) | ||
| } else { | ||
| list, err = scheduler.GetWide(ctx, opts, args...) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch *getOutputFormat { | ||
| case outputFormatYAML: | ||
| err = utils.PrintDetail(os.Stdout, "yaml", list) | ||
| case outputFormatJSON: | ||
| err = utils.PrintDetail(os.Stdout, "json", list) | ||
| default: | ||
| var table string | ||
| table, err = gocsv.MarshalString(list) | ||
| if err != nil { | ||
| break | ||
| } | ||
|
|
||
| utils.PrintTable(table) | ||
| } | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| getOutputFormat = outputFunc(GetCmd) | ||
| SchedulerCmd.AddCommand(GetCmd) | ||
| } |
This file contains hidden or 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,60 @@ | ||
| /* | ||
| Copyright 2025 The Dapr Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package scheduler | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/dapr/cli/pkg/print" | ||
| "github.com/dapr/cli/pkg/scheduler" | ||
| "github.com/dapr/kit/signals" | ||
| ) | ||
|
|
||
| var ( | ||
| schedulerImportFile string | ||
| ) | ||
|
|
||
| var SchedulerImportCmd = &cobra.Command{ | ||
| Use: "import", | ||
| Short: "Import all jobs and actor reminders from a binary file generated by 'dapr scheduler export'.", | ||
| Long: `Import jobs and actor reminders to Scheduler from a binary file generated by 'dapr scheduler export'. | ||
| dapr scheduler import -f export.bin`, | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := signals.Context() | ||
|
|
||
| err := scheduler.Import(ctx, scheduler.ExportImportOptions{ | ||
| SchedulerNamespace: schedulerNamespace, | ||
| KubernetesMode: kubernetesMode, | ||
| TargetFile: schedulerImportFile, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| print.InfoStatusEvent(os.Stdout, "Import from '%s' complete.", schedulerImportFile) | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| SchedulerImportCmd.Flags().MarkHidden("namespace") | ||
| SchedulerImportCmd.Flags().StringVarP(&schedulerImportFile, "input-file", "f", "", "Input file to import jobs and actor reminders from.") | ||
| SchedulerImportCmd.MarkFlagRequired("input-file") | ||
| SchedulerImportCmd.MarkFlagFilename("input-file") | ||
| SchedulerCmd.AddCommand(SchedulerImportCmd) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this command run as
dry-runand only print the number of records to delete and run it with--executewhen you are sure that is the number or reminder you expect to delete? Probably the same fordeletecommandThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but then cli becomes pretty annoying to use. I would rather have a
--dry-runflag.