Implement activity commands#445
Conversation
cretz
left a comment
There was a problem hiding this comment.
Some notes for now and future, but nothing blocking. The existing CLI sure was inconsistent/unclean with these two commands.
| * `--no-json-shorthand-payloads` (bool) - Always all payloads as raw payloads even if they are JSON. | ||
|
|
||
| ### temporal activity: Complete or fail an activity. | ||
|
|
There was a problem hiding this comment.
| Activity commands operate on [Activity Executions](/concepts/what-is-an-activity-execution). | |
| Activity commands follow this syntax: | |
| `temporal activity [command] [command options]` |
Just stole it from old CLI, but I guess not required (we hope to come back and clean these)
There was a problem hiding this comment.
Yes, I'm not in love with that text from the old CLI. I think the help output is pretty clear as-is:
$ temporal activity -h
Complete or fail an activity.
Usage:
temporal activity [command]
Available Commands:
complete Complete an activity.
fail Fail an activity.
and these Markdown links [Activity Executions](/concepts/what-is-an-activity-execution) don't link to a valid target (unless I'm missing something?)
There was a problem hiding this comment.
Not missing anything, I too am not a fan, but I was just leaving many docs things as is to come back and be cleaned up later. Can just leave off too.
| #### Options | ||
|
|
||
| * `--activity-id` (string) - The Activity to be completed. Required. | ||
| * `--identity` (string) - Identity of operator. |
There was a problem hiding this comment.
Previous CLI required this, but I am ok not requiring it
|
|
||
| * `--activity-id` (string) - The Activity to be completed. Required. | ||
| * `--identity` (string) - Identity of operator. | ||
| * `--result` (string) - The result with which to complete the Activity (JSON). Required. |
There was a problem hiding this comment.
This works for me to meet parity. There are a few things we may want in the future to be as robust as --input for workflows:
--resultas astring[]to accept multiple results--result-fileto accept files instead of strings--result-metato support payload metadata--result-base64bool to support base64 binary strings
I wonder if we should create an issue here (same for --detail on failure)
There was a problem hiding this comment.
Not sure this deserves its own file but meh
There was a problem hiding this comment.
Yeah, I wasn't sure how people would like the code arranged. Where would you put it out of interest?
There was a problem hiding this comment.
Probably client, but it doesn't matter. As the utils grow we can move/consolidate as needed
| "go.temporal.io/api/common/v1" | ||
| ) | ||
|
|
||
| func CreatePayloads(data [][]byte, metadata map[string][]byte, isBase64 bool) (*common.Payloads, error) { |
There was a problem hiding this comment.
| func CreatePayloads(data [][]byte, metadata map[string][]byte, isBase64 bool) (*common.Payloads, error) { | |
| func createPayloads(data [][]byte, metadata map[string][]byte, isBase64 bool) (*common.Payloads, error) { |
Probably don't need to export (though it doesn't really matter in the context of an application vs a library so there's no rules here, so nothing required to change)
There was a problem hiding this comment.
OK thanks, my Go style is a work-in-progress... when I uppercased it I was thinking that I was working in a separate "util" package from the main commands, but as you point out that's not the case.
| #### Options | ||
|
|
||
| * `--activity-id` (string) - The Activity to be completed. Required. | ||
| * `--identity` (string) - Identity of operator. |
There was a problem hiding this comment.
It was a bit inconsistent for us to have our CLI accept identity here but not on other commands like start workflow. I wonder if we should accept --identity higher up.
There was a problem hiding this comment.
Agreed; I'd like consistency across all protos that have an identity field. I was just going for parity here.
| return err | ||
| } | ||
|
|
||
| _, err = cl.WorkflowService().RespondActivityTaskCompletedById(cctx, &workflowservice.RespondActivityTaskCompletedByIdRequest{ |
There was a problem hiding this comment.
While this is the approach of the old CLI, cl.CompleteActivityByID would have worked here too (you'd wrap the payload in rawValue). Arguably it'd be cleaner/clearer to use the high-level SDK client, but don't need to change now, but we might consider using the high-level API in the future.
There was a problem hiding this comment.
OK I'm happy to make that change and it would be easy, however, it looks like it doesn't support identity so I'm going to leave it for now.
There was a problem hiding this comment.
Usually smart clients set identity at the client level not the request level. That's what makes the --identity here so strange.
| metadata := map[string][]byte{"encoding": []byte("json/plain")} | ||
| var detailPayloads *common.Payloads | ||
| detailPayloads = nil | ||
| if len(c.Detail) > 0 { | ||
| detailPayloads, err = CreatePayloads([][]byte{[]byte(c.Detail)}, metadata, false) |
There was a problem hiding this comment.
| metadata := map[string][]byte{"encoding": []byte("json/plain")} | |
| var detailPayloads *common.Payloads | |
| detailPayloads = nil | |
| if len(c.Detail) > 0 { | |
| detailPayloads, err = CreatePayloads([][]byte{[]byte(c.Detail)}, metadata, false) | |
| var detailPayloads *common.Payloads | |
| if len(c.Detail) > 0 { | |
| metadata := map[string][]byte{"encoding": []byte("json/plain")} | |
| detailPayloads, err = CreatePayloads([][]byte{[]byte(c.Detail)}, metadata, false) |
Little cleanup
|
Thanks @cretz! Merged to keep the velocity up but there are some threads there we can follow-up in future PRs. |
What was changed
Implement
temporal activity failandtemporal activity completeHow was this tested
samples-python:hello/hello_activity.pyto sleep for a long time in the activity, issued CLI commands (examples below), and confirmed results in web UI.Details
commit 5519021cac3a1d0b9818d903882e0e053ad3df8b (HEAD -> update-reapply) Author: Dan Davison <dan.davison@temporal.io> Date: Mon Feb 12 18:02:34 2024 -0500 Test cli activity commands diff --git a/hello/hello_activity.py b/hello/hello_activity.py index 6615b55..a8a8e54 100644 --- a/hello/hello_activity.py +++ b/hello/hello_activity.py @@ -21,6 +21,7 @@ class ComposeGreetingInput: @activity.defn async def compose_greeting(input: ComposeGreetingInput) -> str: activity.logger.info("Running activity with parameter %s" % input) + await asyncio.sleep(0xFFFFFFFF) return f"{input.greeting}, {input.name}!" @@ -33,7 +34,8 @@ class GreetingWorkflow: return await workflow.execute_activity( compose_greeting, ComposeGreetingInput("Hello", name), - start_to_close_timeout=timedelta(seconds=10), + start_to_close_timeout=timedelta(seconds=0xFFFFFFFF), + activity_id="MyActivityId", )Example commands tested