2323from application_sdk .clients .workflow import WorkflowClient
2424from application_sdk .constants import (
2525 APPLICATION_NAME ,
26+ DEPLOYMENT_NAME ,
2627 MAX_CONCURRENT_ACTIVITIES ,
2728 WORKFLOW_AUTH_ENABLED ,
2829 WORKFLOW_HOST ,
@@ -265,13 +266,16 @@ def __init__(
265266 def get_worker_task_queue (self ) -> str :
266267 """Get the worker task queue name.
267268
268- The task queue name is derived from the application name and is used
269- to route workflow tasks to appropriate workers.
269+ The task queue name is derived from the application name and deployment name
270+ and is used to route workflow tasks to appropriate workers.
270271
271272 Returns:
272- str: The task queue name, which is the same as the application name .
273+ str: The task queue name in format "app_name-deployment_name" .
273274 """
274- return self .application_name
275+ if DEPLOYMENT_NAME :
276+ return f"{ self .application_name } -{ DEPLOYMENT_NAME } "
277+ else :
278+ return self .application_name
275279
276280 def get_connection_string (self ) -> str :
277281 """Get the Temporal server connection string.
@@ -307,10 +311,13 @@ async def load(self) -> None:
307311 ConnectionError: If connection to the Temporal server fails.
308312 ValueError: If authentication is enabled but credentials are missing.
309313 """
314+ # Set TLS based on host - disable for localhost/127.0.0.1, enable for others
315+ tls_enabled = self .host not in ["127.0.0.1" , "localhost" ]
316+
310317 connection_options : Dict [str , Any ] = {
311318 "target_host" : self .get_connection_string (),
312319 "namespace" : self .namespace ,
313- "tls" : True ,
320+ "tls" : tls_enabled ,
314321 }
315322
316323 if self .auth_enabled :
@@ -355,12 +362,24 @@ async def start_workflow(
355362 WorkflowFailureError: If the workflow fails to start.
356363 ValueError: If the client is not loaded.
357364 """
365+ # Check if credentials should be stored based on credentialSource
366+ should_store_credentials = False
358367 if "credentials" in workflow_args :
359- # remove credentials from workflow_args and add reference to credentials
360- workflow_args ["credential_guid" ] = SecretStoreOutput .store_credentials (
361- workflow_args ["credentials" ]
362- )
363- del workflow_args ["credentials" ]
368+ credential_source = workflow_args ["credentials" ].get ("credentialSource" , "" )
369+ should_store_credentials = credential_source == "direct"
370+
371+ if should_store_credentials :
372+ # Only store credentials if credentialSource is "direct"
373+ workflow_args ["credential_guid" ] = SecretStoreOutput .store_credentials (
374+ workflow_args ["credentials" ]
375+ )
376+ del workflow_args ["credentials" ]
377+ else :
378+ # For non-direct credential sources, keep credentials in workflow_args
379+ # but don't store them in SecretStore
380+ logger .info (
381+ f"Skipping credential storage for credentialSource: { credential_source } "
382+ )
364383
365384 workflow_id = workflow_args .get ("workflow_id" )
366385 output_prefix = workflow_args .get ("output_prefix" , "/tmp/output" )
@@ -376,19 +395,36 @@ async def start_workflow(
376395 }
377396 )
378397
398+ # Determine configuration approach based on credential storage
399+ if should_store_credentials :
400+ # StateStore approach - store configuration and pass only workflow_id with flag
379401 StateStoreOutput .store_configuration (workflow_id , workflow_args )
380-
381- logger .info (f"Created workflow config with ID: { workflow_id } " )
402+ args = [{"workflow_id" : workflow_id , "_use_statestore" : True }]
403+ logger .info (
404+ f"Created workflow config with ID: { workflow_id } (StateStore approach)"
405+ )
406+ else :
407+ # Direct approach - pass full configuration with flag
408+ workflow_args ["_use_statestore" ] = False
409+ args = [workflow_args ]
410+ logger .info (f"Created workflow with ID: { workflow_id } (direct approach)" )
382411
383412 try :
384- # Pass the full workflow_args to the workflow
413+ # Get task_queue from workflow_args or credentials or use default
414+ task_queue = (
415+ workflow_args .get ("task_queue" )
416+ or workflow_args .get ("credentials" , {}).get ("task_queue" )
417+ or self .worker_task_queue
418+ )
419+
420+ # Pass the conditional args to the workflow
385421 if not self .client :
386422 raise ValueError ("Client is not loaded" )
387423 handle = await self .client .start_workflow (
388424 workflow_class , # type: ignore
389- args = [{ "workflow_id" : workflow_id }] ,
425+ args = args ,
390426 id = workflow_id ,
391- task_queue = self . worker_task_queue ,
427+ task_queue = task_queue ,
392428 cron_schedule = workflow_args .get ("cron_schedule" , "" ),
393429 execution_timeout = WORKFLOW_MAX_TIMEOUT_HOURS ,
394430 )
0 commit comments