-
Notifications
You must be signed in to change notification settings - Fork 127
RSDK-12536: Jobs CLI Parity #5731
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
Open
allisonschiang
wants to merge
14
commits into
viamrobotics:main
Choose a base branch
from
allisonschiang:RSDK-12536
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+612
−23
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
37e2305
init
allisonschiang a0136ad
Update client.go
allisonschiang 23007af
description
allisonschiang f4f9427
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into RSDK-12536
allisonschiang 07437c6
Update app.go
allisonschiang 21bb55d
Update client.go
allisonschiang bfe9324
init form
allisonschiang 332733d
Update client.go
allisonschiang 00120cd
update format
allisonschiang 4e5a6a0
reject resources not in config
allisonschiang 9708dc3
update parts flag
allisonschiang 1902f74
comments
allisonschiang 36a60fc
Update client.go
allisonschiang eb68b1b
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into RSDK-12536
allisonschiang 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ const ( | |
| generalFlagNoProgress = "no-progress" | ||
| generalFlagAPI = "api" | ||
| generalFlagArgs = "args" | ||
| generalFlagAttributes = "attributes" | ||
| generalFlagDryRun = "dry-run" | ||
|
|
||
| moduleFlagLanguage = "language" | ||
|
|
@@ -175,34 +176,40 @@ const ( | |
| xacroFlagROSDistro = "ros-distro" | ||
| ) | ||
|
|
||
| var commonPartFlags = []cli.Flag{ | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagPart, | ||
| Aliases: []string{generalFlagPartID, generalFlagPartName}, | ||
| Required: true, | ||
| // partFlags builds the standard part/org/location/machine flag set. | ||
| // partRequired controls whether --part is mandatory. | ||
| func partFlags(partRequired bool) []cli.Flag { | ||
| return []cli.Flag{ | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagPart, | ||
| Aliases: []string{generalFlagPartID, generalFlagPartName}, | ||
| Required: partRequired, | ||
| }, | ||
| }, | ||
| }, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagOrganization, | ||
| Aliases: []string{generalFlagAliasOrg, generalFlagOrgID, generalFlagAliasOrgName}, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagOrganization, | ||
| Aliases: []string{generalFlagAliasOrg, generalFlagOrgID, generalFlagAliasOrgName}, | ||
| }, | ||
| }, | ||
| }, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagLocation, | ||
| Aliases: []string{generalFlagLocationID, generalFlagAliasLocationName}, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagLocation, | ||
| Aliases: []string{generalFlagLocationID, generalFlagAliasLocationName}, | ||
| }, | ||
| }, | ||
| }, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagMachine, | ||
| Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, | ||
| &AliasStringFlag{ | ||
| cli.StringFlag{ | ||
| Name: generalFlagMachine, | ||
| Aliases: []string{generalFlagAliasRobot, generalFlagMachineID, generalFlagMachineName}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| var commonPartFlags = partFlags(true) | ||
|
|
||
| var commonOtlpFlags = []cli.Flag{ | ||
| &cli.StringFlag{ | ||
| Name: "endpoint", | ||
|
|
@@ -2784,6 +2791,84 @@ Note: There is no progress meter while copying is in progress. | |
| }, | ||
| Action: createCommandWithT[machinesPartRunArgs](MachinesPartRunAction), | ||
| }, | ||
| { | ||
| Name: "add-job", | ||
| Usage: "add a scheduled job to a machine part", | ||
| Description: `Add a scheduled job that runs a method on a resource at a given interval. | ||
|
|
||
| With --attributes, pass a single JSON object (inline or path to a JSON file) with: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should I delete the description for using the -attributes tag if we want to encourage the interactive flow? viam module generate doesn't advertise the flag path |
||
| name (required) unique name for this job | ||
| schedule (required) must be one of: | ||
| "continuous" run in a loop without stopping | ||
| a Go duration e.g. "5s", "1h30m", "500ms" | ||
| a cron expr e.g. "0 0 * * *" (5-field) or "*/5 * * * * *" (6-field with seconds) | ||
| resource (required) name of the component or service to run the method on | ||
| method (required) gRPC method name, e.g. "DoCommand", "GetReadings" | ||
| command (optional) JSON object passed as the argument to DoCommand | ||
| log_configuration (optional) e.g. {"level":"debug"}. Level must be one of: debug, info, warn, error | ||
|
|
||
| Example (interactive prompt): | ||
| viam machines part add-job | ||
|
|
||
| Example with inline JSON: | ||
| viam machines part add-job --part=<part-id> \ | ||
| --attributes '{"name":"my-job","schedule":"1h","resource":"my-sensor","method":"GetReadings"}' | ||
|
|
||
| Example with a JSON file: | ||
| viam machines part add-job --part=<part-id> --attributes ./job.json`, | ||
| UsageText: createUsageText("machines part add-job", []string{generalFlagPart, generalFlagAttributes}, true, false), | ||
| Flags: append(partFlags(false), &cli.StringFlag{ | ||
| Name: generalFlagAttributes, | ||
| Required: false, | ||
| Usage: "JSON job config or path to JSON file; omit to use the interactive form", | ||
| }), | ||
| Action: createCommandWithT(machinesPartAddJobAction), | ||
| }, | ||
| { | ||
| Name: "update-job", | ||
| Usage: "update a scheduled job on a machine part", | ||
| Description: `Update an existing job's configuration by name. The --attributes flag accepts a single JSON | ||
| object (inline or a path to a JSON file) with the fields to change. Only the fields provided will | ||
| be updated; all other fields remain unchanged. The job name cannot be changed. | ||
|
|
||
| Example changing the schedule: | ||
| viam machines part update-job --part=<part-id> --name=my-job --attributes '{"schedule":"30m"}' | ||
|
|
||
| Example changing multiple fields: | ||
| viam machines part update-job --part=<part-id> --name=my-job \ | ||
| --attributes '{"schedule":"0 0 * * *","method":"DoCommand","command":{"action":"reset"}}'`, | ||
| UsageText: createUsageText( | ||
| "machines part update-job", | ||
| []string{generalFlagPart, generalFlagName, generalFlagAttributes}, true, false), | ||
| Flags: append(commonPartFlags, []cli.Flag{ | ||
| &cli.StringFlag{ | ||
| Name: generalFlagName, | ||
| Required: true, | ||
| Usage: "name of the job to update", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: generalFlagAttributes, | ||
| Required: true, | ||
| Usage: "JSON job config or path to JSON file with fields to update", | ||
| }, | ||
| }...), | ||
| Action: createCommandWithT(machinesPartUpdateJobAction), | ||
| }, | ||
| { | ||
| Name: "delete-job", | ||
| Usage: "delete a scheduled job from a machine part", | ||
| Description: `Delete an existing job by name. | ||
|
|
||
| Example: | ||
| viam machines part delete-job --part=<part-id> --name=my-job`, | ||
| UsageText: createUsageText("machines part delete-job", []string{generalFlagPart, generalFlagName}, true, false), | ||
| Flags: append(commonPartFlags, &cli.StringFlag{ | ||
| Name: generalFlagName, | ||
| Required: true, | ||
| Usage: "name of the job to delete", | ||
| }), | ||
| Action: createCommandWithT(machinesPartDeleteJobAction), | ||
| }, | ||
| { | ||
| Name: "shell", | ||
| Usage: "start a shell on a machine part", | ||
|
|
||
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.
if we want users to be able to input part id within the interactive huh form, we need to create a wrapper around the commonPartFlags so it can take part-id as an optional input (and won't instantly reject add-job if there's no part-id)