temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
209 stars 142 forks source link

Pluggable activity name provider #396

Open mfateev opened 3 years ago

mfateev commented 3 years ago

Is your feature request related to a problem? Please describe. The activity type name is automatically generated from its method name. Different users of the SDK have different opinions on how this name should be generated. For example, see this forum post.

Describe the solution you'd like The proposal is to make activity name generation pluggable through ClientOptions and WorkerOptions. This way each user can implement its own standard to name activities automatically.

vitarb commented 3 years ago

Also consider feature request made in #467 we might be able to come up with a solution that addresses both at the same time.

kkuntim commented 1 year ago

We also need this feature; any suggestion on how to implement the same.

kkuntim commented 1 year ago

Capturing our requirement.

  1. Say I have a DB table migration activity ("migrateTable") and based on need we might end up calling the same activity multiple times for migrating n Tables
  2. We would like to see the activities as "migrateTable1", "migrateTable2"... instead of "migrateTable
  3. We have defined a name for Activity (using Annotation)
  4. We are able to change the AcvityName in Workflow Implementation code by overriding name Annotation value.
  5. The challenge lies in Registering and Starting workers; as we might not know how many times we will end up calling the activity (hence different Names) during workflow execution (in case we are calling the Actitvity in loop).

Is there a workaround or can we Map same Activity in Worker to Renamed Activities in Workflow Implementation call. Please suggest... where to make this code change in Java SDk

Thanks in advance Krishnendu

kkuntim commented 1 year ago

Hi @mfateev Any suggestions on implementation approach. Thank you.

kkuntim commented 1 year ago

I have two approach in mind:

  1. Instead of exact typename match for a Activity we can go for a pattern match and derive the activity Name from Activity Stub call.
  2. Have some kind of out of the box attribute list for Activity and have API to populate the same. Please suggest...

Thank you Krishnendu

Quinn-With-Two-Ns commented 1 year ago

@kkuntim From your requirements it sounds like you want activity names to be generated dynamically base on the activity input? Activity names must be know at worker startup time for routing so this feature cannot meet your requirements.

I think this issue to allow passing some metadata with commands would be a better fit. We could allow passing along a label metadata field for activities and child workflows that you could specify how you want and use in the UI.

mfateev commented 1 year ago

I believe you can implement this logic by implementing custom WorkflowOutboundCallsInterceptor.