o
    i#&                     @  s4  U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddl m!Z! dd	lm"Z# dd
lm$Z$ ddl%m&Z& eG dd dZ'eG dd dZ(eG dd dZ)ee(e)f Z*de+d< eG dd dZ,eG dd dZ-eG dd dZ.eG dd dZ/ee.e-e/f Z0de+d< eG dd dZ1eG dd  d Z2ed!d"G d#d$ d$Z3ee3e2e#f Z4de+d%< eG d&d' d'Z5G d(d) d)Z6G d*d+ d+e!Z7d;d4d5Z8d<d9d:Z9dS )=zkWorker using SDK Core. (unstable)

Nothing in this module should be considered stable. The API may change.
    )annotations)	dataclass)		AwaitableCallableListMutableSequenceOptionalSequenceSetTupleUnion)	TypeAliasN)Payload)VisitorFunctions)CustomSlotSupplier)PollShutdownError)CommandAwarePayloadVisitorc                   @  s   e Zd ZU dZded< ded< ded< ded< d	ed
< ded< ded< ded< ded< ded< d	ed< d	ed< d	ed< ded< ded< d	ed< ded< ded< ded< dS ) WorkerConfigzBPython representation of the Rust struct for configuring a worker.str	namespace
task_queueWorkerVersioningStrategyversioning_strategyzOptional[str]identity_overrideintmax_cached_workflowsTunerHoldertunerPollerBehaviorworkflow_task_poller_behaviorfloatnonsticky_to_sticky_poll_ratioactivity_task_poller_behaviorboolno_remote_activities-sticky_queue_schedule_to_start_timeout_millis&max_heartbeat_throttle_interval_millis*default_heartbeat_throttle_interval_milliszOptional[float]max_activities_per_second$max_task_queue_activities_per_secondgraceful_shutdown_period_millisnondeterminism_as_workflow_failzSet[str])nondeterminism_as_workflow_fail_for_typesnexus_task_poller_behaviorN__name__
__module____qualname____doc____annotations__ r4   r4   ^/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/bridge/worker.pyr   ,   s*   
 r   c                   @     e Zd ZU dZded< dS )PollerBehaviorSimpleMaximumzDPython representation of the Rust struct for simple poller behavior.r   simple_maximumNr.   r4   r4   r4   r5   r7   E      
 r7   c                   @  s*   e Zd ZU dZded< ded< ded< dS )PollerBehaviorAutoscalingzIPython representation of the Rust struct for autoscaling poller behavior.r   minimummaximuminitialNr.   r4   r4   r4   r5   r:   L   s
   
 r:   r   r   c                   @  "   e Zd ZU dZded< ded< dS )WorkerDeploymentVersionzUPython representation of the Rust struct for configuring a worker deployment version.r   deployment_namebuild_idNr.   r4   r4   r4   r5   r?   [      
 r?   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	WorkerDeploymentOptionszUPython representation of the Rust struct for configuring a worker deployment options.r?   versionr#   use_worker_versioningr   default_versioning_behaviorNr.   r4   r4   r4   r5   rC   c   s   
 rC   c                   @  r6   )WorkerVersioningStrategyNonez[Python representation of the Rust struct for configuring a worker versioning strategy None.r   build_id_no_versioningNr.   r4   r4   r4   r5   rG   m   r9   rG   c                   @  r6   )*WorkerVersioningStrategyLegacyBuildIdBasedzlPython representation of the Rust struct for configuring a worker versioning strategy legacy Build ID-based.r   build_id_with_versioningNr.   r4   r4   r4   r5   rI   t   r9   rI   r   c                   @  r>   )ResourceBasedTunerConfigzPPython representation of the Rust struct for configuring a resource-based tuner.r    target_memory_usagetarget_cpu_usageNr.   r4   r4   r4   r5   rK      rB   rK   c                   @  s2   e Zd ZU dZded< ded< ded< ded< dS )	ResourceBasedSlotSupplierzLPython representation of the Rust struct for a resource-based slot supplier.r   minimum_slotsmaximum_slotsramp_throttle_msrK   tuner_configNr.   r4   r4   r4   r5   rN         
 rN   T)frozenc                   @  r6   )FixedSizeSlotSupplierzHPython representation of the Rust struct for a fixed-size slot supplier.r   	num_slotsNr.   r4   r4   r4   r5   rU      r9   rU   SlotSupplierc                   @  s2   e Zd ZU dZded< ded< ded< ded< dS )r   z<Python representation of the Rust struct for a tuner holder.rW   workflow_slot_supplieractivity_slot_supplierlocal_activity_slot_suppliernexus_slot_supplierNr.   r4   r4   r4   r5   r      rS   r   c                   @  s   e Zd ZdZed6ddZed7ddZd8ddZd9ddZd:ddZ	d;ddZ
d<ddZd=d d!Zd>d#d$Zd?d&d'Zd@d)d*ZdAd-d.ZdBd/d0Zd9d1d2Zd9d3d4Zd5S )CWorkerzSDK Core worker.clienttemporalio.bridge.client.Clientconfigr   returnc                 C  s   t tjj| jj| j|S )z,Create a bridge worker from a bridge client.)r\   
temporaliobridgetemporal_sdk_bridge
new_worker_runtime_ref)r]   r_   r4   r4   r5   create   s
   zWorker.createruntime!temporalio.bridge.runtime.RuntimeBTuple[Worker, temporalio.bridge.temporal_sdk_bridge.HistoryPusher]c                 C  s"   t jj| j|\}}t||fS )zCreate a bridge replay worker.)ra   rb   rc   new_replay_workerrf   r\   )rh   r_   replay_workerpusherr4   r4   r5   
for_replay   s   	zWorker.for_replayref/temporalio.bridge.temporal_sdk_bridge.WorkerRefNonec                 C  s
   || _ dS )z,Create SDK core worker from a bridge worker.N)rf   selfro   r4   r4   r5   __init__   s   
zWorker.__init__c                   s   | j  I dH  dS )zValidate the bridge worker.N)rf   validaters   r4   r4   r5   ru      s   zWorker.validate>temporalio.bridge.proto.workflow_activation.WorkflowActivationc                       t jjjj| j I dH S )zPoll for a workflow activation.N)ra   rb   protoworkflow_activationWorkflowActivation
FromStringrf   poll_workflow_activationrv   r4   r4   r5   r}      s
   zWorker.poll_workflow_activation2temporalio.bridge.proto.activity_task.ActivityTaskc                   rx   )zPoll for an activity task.N)ra   rb   ry   activity_taskActivityTaskr|   rf   poll_activity_taskrv   r4   r4   r5   r         zWorker.poll_activity_task'temporalio.bridge.proto.nexus.NexusTaskc                   rx   )zPoll for a nexus task.N)ra   rb   ry   nexus	NexusTaskr|   rf   poll_nexus_taskrv   r4   r4   r5   r      r   zWorker.poll_nexus_taskcompHtemporalio.bridge.proto.workflow_completion.WorkflowActivationCompletionc                      | j | I dH  dS )zComplete a workflow activation.N)rf   complete_workflow_activationSerializeToStringrs   r   r4   r4   r5   r      s   z#Worker.complete_workflow_activation.temporalio.bridge.proto.ActivityTaskCompletionc                   r   )zComplete an activity task.N)rf   complete_activity_taskr   r   r4   r4   r5   r         zWorker.complete_activity_task1temporalio.bridge.proto.nexus.NexusTaskCompletionc                   r   )zComplete a nexus task.N)rf   complete_nexus_taskr   r   r4   r4   r5   r      r   zWorker.complete_nexus_task)temporalio.bridge.proto.ActivityHeartbeatc                 C  s   | j |  dS )zRecord an activity heartbeat.N)rf   record_activity_heartbeatr   r   r4   r4   r5   r      s   z Worker.record_activity_heartbeatrun_idr   c                 C  s   | j | dS )zRequest a workflow be evicted.N)rf   request_workflow_eviction)rs   r   r4   r4   r5   r     s   z Worker.request_workflow_evictionc                 C  s   | j |j  dS )zReplace the worker client.N)rf   replace_client)rs   r]   r4   r4   r5   r     s   zWorker.replace_clientc                 C  s   | j   dS )zStart shutdown of the worker.N)rf   initiate_shutdownrv   r4   r4   r5   r   	  s   zWorker.initiate_shutdownc                   s    | j }d| _ | I dH  dS )zFinalize the worker.

        This will fail if shutdown hasn't completed fully due to internal
        reference count checks.
        N)rf   finalize_shutdownrr   r4   r4   r5   r     s   zWorker.finalize_shutdownN)r]   r^   r_   r   r`   r\   )rh   ri   r_   r   r`   rj   )ro   rp   r`   rq   )r`   rq   )r`   rw   )r`   r~   )r`   r   )r   r   r`   rq   )r   r   r`   rq   )r   r   r`   rq   )r   r   r`   rq   )r   r   r`   rq   )r]   r^   r`   rq   )r/   r0   r1   r2   staticmethodrg   rn   rt   ru   r}   r   r   r   r   r   r   r   r   r   r   r4   r4   r4   r5   r\      s&    












r\   c                   @  s*   e Zd ZdddZdd	d
ZdddZdS )_Visitorf7Callable[[Sequence[Payload]], Awaitable[List[Payload]]]c                 C  s
   || _ d S )N)_f)rs   r   r4   r4   r5   rt     s   
z_Visitor.__init__payloadr   r`   rq   c                   s2   |  |gI d H d }||ur|| d S d S Nr   )r   CopyFrom)rs   r   new_payloadr4   r4   r5   visit_payload  s
   z_Visitor.visit_payloadpayloadsMutableSequence[Payload]c                   sF   t |dkr	d S | |I d H }||u rd S |d d = || d S r   )lenr   extend)rs   r   new_payloadsr4   r4   r5   visit_payloads!  s   
z_Visitor.visit_payloadsN)r   r   )r   r   r`   rq   )r   r   r`   rq   )r/   r0   r1   rt   r   r   r4   r4   r4   r5   r     s    

r   
activationrw   codec!temporalio.converter.PayloadCodecdecode_headersr#   r`   rq   c                   (   t d| dt|j| I dH  dS )z&Decode all payloads in the activation.Tskip_search_attributesskip_headersN)r   visitr   decode)r   r   r   r4   r4   r5   decode_activation+     r   
completionr   encode_headersc                   r   )z&Encode all payloads in the completion.Tr   N)r   r   r   encode)r   r   r   r4   r4   r5   encode_completion6  r   r   )r   rw   r   r   r   r#   r`   rq   )r   r   r   r   r   r#   r`   rq   ):r2   
__future__r   dataclassesr   typingr   r   r   r   r   r	   r
   r   r   typing_extensionsr   temporalio.api.common.v1ra   temporalio.api.history.v1temporalio.bridge.clienttemporalio.bridge.proto%temporalio.bridge.proto.activity_tasktemporalio.bridge.proto.nexus+temporalio.bridge.proto.workflow_activation+temporalio.bridge.proto.workflow_completiontemporalio.bridge.runtime%temporalio.bridge.temporal_sdk_bridgetemporalio.convertertemporalio.exceptions$temporalio.api.common.v1.message_pb2r   temporalio.bridge._visitorr   r   BridgeCustomSlotSupplierr   (temporalio.worker._command_aware_visitorr   r   r7   r:   r   r3   r?   rC   rG   rI   r   rK   rN   rU   rW   r   r\   r   r   r   r4   r4   r4   r5   <module>   s    ,			l
