Skip to content
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

Implement schedule commands #459

Merged
merged 32 commits into from
Mar 22, 2024
Merged

Conversation

dnr
Copy link
Member

@dnr dnr commented Feb 15, 2024

What was changed

Implement schedule commands for new CLI.

Why?

Feature parity.

Checklist

  1. Closes

  2. How was this tested:

new tests

  1. Any docs updates needed?
  • The format of temporal schedule describe -o json changed to the --raw format of the previous cli.

@dnr dnr changed the title Implement schedule commands [incomplete] Implement schedule commands Mar 15, 2024
@dnr dnr marked this pull request as ready for review March 15, 2024 06:47
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Didn't pour over every output detail or anything.

temporalcli/commandsmd/commands.md Show resolved Hide resolved
temporalcli/commands.schedule.go Outdated Show resolved Hide resolved
Comment on lines 83 to 84
// For json: this doesn't come out as proper protojson, the field names are
// day_of_month instead of dayOfMonth.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the cost of mixing proto and non-proto JSON but there's not an east solution. What we do in some other commands is separate the JSON representation structs from the text ones, and for JSON, make this be something like []json.Message instead where we pre-JSON it. It became too confusing for complicated models to try to satisfy JSON and non-JSON needs with the same model (but if you must reuse models, consider more explicit JSON models then that meet the JSON field name needs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding a special case for slices in the printer.. I hope that's acceptable. With that, and a couple specialized structs in here, I think the text output for specs is much nicer.

For json, I realized I was making the problem much harder than it had to be: I just made -o json do what --raw did, for both describe and list. There's no reason at all to have two different json outputs.

Copy link
Member

@cretz cretz Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up adding a special case for slices in the printer.. I hope that's acceptable.

Works for me, not sure we've had a stance on nested slice printing so I don't mind making it friendlier. Looks like it breaks a test, so may have to update that.

For json, I realized I was making the problem much harder than it had to be: I just made -o json do what --raw did, for both describe and list. There's no reason at all to have two different json outputs.

Also works for me, because I find proto to be more stable and documented than CLI-specific structs anyways (but have to resort to specific structs when needing to combine of course)

Comment on lines 34 to 35
// TODO: should we include any other fields here, e.g. jitter, time zone, start/end time
out := &printableSchedule{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I'd expect describing to return everything available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added most of the data that's in the schedule description. Also rearranged a bunch of stuff and changed some formatting. I'm not sure it's great but it's closer.

temporalcli/commands.schedule.go Outdated Show resolved Hide resolved
@Sushisource
Copy link
Member

Also appears this will close #433 - if that's true can you update the description to close that when this is merged?

@dnr
Copy link
Member Author

dnr commented Mar 21, 2024

Also appears this will close #433 - if that's true can you update the description to close that when this is merged?

Not really, it just prints memo/search attrs in list, but not update them.

@dnr dnr force-pushed the cli-rewrite-schedule branch from 595e771 to f888d67 Compare March 21, 2024 05:18
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just want to bring that test time down

temporalcli/commands_test.go Outdated Show resolved Hide resolved
temporalcli/commands.schedule_test.go Outdated Show resolved Hide resolved
res := s.createSchedule("--interval", "2s")
s.NoError(res.Err)

time.Sleep(4 * time.Second) // run at least once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid sleeps in tests? Can we do some kind of manual trigger/backfill here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do a manual trigger, yeah. I wanted to keep the tests more orthogonal and use a normal scheduled run here, but I guess it doesn't matter.

temporalcli/commands.schedule_test.go Show resolved Hide resolved
res := s.createSchedule("--interval", "2s")
s.NoError(res.Err)

time.Sleep(4 * time.Second) // run at least once
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do a manual trigger, yeah. I wanted to keep the tests more orthogonal and use a normal scheduled run here, but I guess it doesn't matter.

temporalcli/commands.schedule_test.go Show resolved Hide resolved
temporalcli/commands_test.go Outdated Show resolved Hide resolved
WorkflowTaskTimeout: opts.WorkflowTaskTimeout,
// RetryPolicy not supported yet
// TODO: buildStartOptions doesn't fill in TypedSearchAttributes, this doesn't work yet:
TypedSearchAttributes: opts.TypedSearchAttributes,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cretz @Quinn-With-Two-Ns What do you think is the best way to handle this right now?

The situation appears to be: buildStartOptions builds search attributes in the form map[string]any (very easy to do from json) and puts them in StartWorkflowOptions.SearchAttributes. This is deprecated, but it still works for starting workflows.

For ScheduleWorkflowAction though, apparently untyped support is gone completely? The comment on UntypedSearchAttributes says This should never be used for create. Even if I could use it, it's a map[string]*commonpb.Payload which means I'd have to convert to Payloads (a little more work but not a huge deal).

To set TypedSearchAttributes, though, it looks like I'd have to do a lot of work. Basically it would have to look a lot like convertToTypedSearchAttributes from internal/internal_search_attributes.go, except with reflection?

I understand the goal of typed search attributes is to make them hard to use in a generic way, but the cli kinda needs to use them in a generic way 🫤 (So does "modify schedule search attributes" btw, except that's from workflow context so the code has to be different again.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ug, yeah, we've hit this a few times now with generic tools. If the UntypedSearchAttributes does work for now I think it's ok to use here and just assume that warning is for users only. The problem is technically a search attribute key for setting is supposed to be defined by its name and type, but we have no reasonable interface for that in CLI.

Note the starting of workflows sets untyped search attributes too, we were just forced to remove the either-or option on schedules because this same type is used for update and we couldn't tell which was the intended field on update (it was a long discussion internally before we made this backwards compatibility break and we documented it in release notes).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed UntypedSearchAttributes in the start workflow action works for create schedule so I used that for now (sorry Quinn) and added a test.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are obvious flag incompatibilities with today's CLI schedule command, can you mention those in the PR description? We're going to go across the PRs and collect them when we make our first release.

@dnr
Copy link
Member Author

dnr commented Mar 22, 2024

If there are obvious flag incompatibilities with today's CLI schedule command, can you mention those in the PR description? We're going to go across the PRs and collect them when we make our first release.

I'm not aware of any big incompatibilities, though there may be some small ones. The non-raw describe json output is different, but that's why --raw was advised before. Now it's just -o json

@dnr dnr merged commit 1e26acb into temporalio:cli-rewrite Mar 22, 2024
6 checks passed
@dnr dnr deleted the cli-rewrite-schedule branch March 22, 2024 22:19
@cretz
Copy link
Member

cretz commented Mar 25, 2024

👍 No concerns about output compatibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants