
    i?1it[                       d dl mZ d dlmZmZmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZ d dlmZmZ d dlmZmZ d d	lmZmZ erd d
lmZmZ 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ  G d de      Z! G d de      Z"y)    )annotations)TYPE_CHECKINGAnycast)"filter_out_none_values_recursivelyignore_docsmaybe_extract_enum_member_valueparse_date_fields)ApifyApiError)catch_not_found_or_throwencode_webhook_list_to_base64
pluck_data)ResourceClientResourceClientAsync)	RunClientRunClientAsync)RunCollectionClientRunCollectionClientAsync)WebhookCollectionClientWebhookCollectionClientAsync)ActorJobStatus
MetaOriginNc                    | |||||d||dS )z,Get the dictionary representation of a task.)buildmaxItemsmemoryMbytestimeoutSecs)actIdnameoptionsinputtitle )actor_idr   
task_inputr   	max_itemsmemory_mbytestimeout_secsr"   s           t/home/www/therecruiter.miabetepe.com/venv/lib/python3.12/site-packages/apify_client/clients/resource_clients/task.pyget_task_representationr*      s-     !)'	
      c                  "    e Zd ZdZed fd       ZddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	dddddddd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
ddZddZddZdddddZddZ xZS )
TaskClientz*Sub-client for manipulating a single task.c                L    |j                  dd      }t        |   |d|i| y)zInitialize the TaskClient.resource_pathactor-tasksNpopsuper__init__selfargskwargsr/   	__class__s       r)   r4   zTaskClient.__init__3   ,     

?MB$FmFvFr+   c                "    | j                         S )Retrieve the task.

        https://docs.apify.com/api/v2#/reference/actor-tasks/task-object/get-task

        Returns:
            dict, optional: The retrieved task
        _getr6   s    r)   getzTaskClient.get9   s     yy{r+   Nr   r%   r   r&   r'   r(   r"   c          	     Z    t        |||||||      }| j                  t        |            S )  Update the task with specified fields.

        https://docs.apify.com/api/v2#/reference/actor-tasks/task-object/update-task

        Args:
            name (str, optional): Name of the task
            build (str, optional): Actor build to run. It can be either a build tag or build number.
                                   By default, the run uses the build specified in the task settings (typically latest).
            max_items (int, optional): Maximum number of results that will be returned by this run.
                                       If the Actor is charged per result, you will not be charged for more results than the given limit.
            memory_mbytes (int, optional): Memory limit for the run, in megabytes.
                                           By default, the run uses a memory limit specified in the task settings.
            timeout_secs (int, optional): Optional timeout for the run, in seconds. By default, the run uses timeout specified in the task settings.
            task_input (dict, optional): Task input dictionary
            title (str, optional): A human-friendly equivalent of the name

        Returns:
            dict: The updated task
        rA   r*   _updater   	r6   r   r%   r   r&   r'   r(   r"   task_representations	            r)   updatezTaskClient.updateC   s<    < 6!'%
 ||>?RSTTr+   c                "    | j                         S )oDelete the task.

        https://docs.apify.com/api/v2#/reference/actor-tasks/task-object/delete-task
        _deleter?   s    r)   deletezTaskClient.deletem   s    
 ||~r+   r%   r   r&   r'   r(   wait_for_finishwebhooksc          
         | j                  ||||||t        |      nd      }| j                  j                  | j	                  d      dddi||      }	t        t        |	j                                     S a  Start the task and immediately return the Run object.

        https://docs.apify.com/api/v2#/reference/actor-tasks/run-collection/run-task

        Args:
            task_input (dict, optional): Task input dictionary
            build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
                                   By default, the run uses the build specified in the task settings (typically latest).
            max_items (int, optional): Maximum number of results that will be returned by this run.
                                       If the Actor is charged per result, you will not be charged for more results than the given limit.
            memory_mbytes (int, optional): Memory limit for the run, in megabytes.
                                           By default, the run uses a memory limit specified in the task settings.
            timeout_secs (int, optional): Optional timeout for the run, in seconds. By default, the run uses timeout specified in the task settings.
            wait_for_finish (int, optional): The maximum number of seconds the server waits for the run to finish.
                                               By default, it is 0, the maximum value is 60.
            webhooks (list of dict, optional): Optional ad-hoc webhooks (https://docs.apify.com/webhooks/ad-hoc-webhooks)
                                               associated with the actor run which can be used to receive a notification,
                                               e.g. when the actor finished or failed.
                                               If you already have a webhook set up for the actor or task, you do not have to add it again here.
                                               Each webhook is represented by a dictionary containing these items:
                                               * ``event_types``: list of ``WebhookEventType`` values which trigger the webhook
                                               * ``request_url``: URL to which to send the webhook HTTP request
                                               * ``payload_template`` (optional): Optional template for the request payload

        Returns:
            dict: The run object
        N)r   r   memorytimeoutwaitForFinishrP   runsPOSTzcontent-typezapplication/json; charset=utf-8)urlmethodheadersjsonparams_paramsr   http_clientcall_urlr
   r   r[   
r6   r%   r   r&   r'   r(   rO   rP   request_paramsresponses
             r)   startzTaskClient.startt   s    L   )@H@T28<Z^ & 
 ##((		&!#%FG! ) 
 !HMMO!<==r+   r%   r   r&   r'   r(   rP   	wait_secsc                   | j                  ||||||      }| j                  j                  |d         j                  |      S )  Start a task and wait for it to finish before returning the Run object.

        It waits indefinitely, unless the wait_secs argument is provided.

        https://docs.apify.com/api/v2#/reference/actor-tasks/run-collection/run-task

        Args:
            task_input (dict, optional): Task input dictionary
            build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
                                   By default, the run uses the build specified in the task settings (typically latest).
            max_items (int, optional): Maximum number of results that will be returned by this run.
                                       If the Actor is charged per result, you will not be charged for more results than the given limit.
            memory_mbytes (int, optional): Memory limit for the run, in megabytes.
                                           By default, the run uses a memory limit specified in the task settings.
            timeout_secs (int, optional): Optional timeout for the run, in seconds. By default, the run uses timeout specified in the task settings.
            webhooks (list, optional): Specifies optional webhooks associated with the actor run, which can be used to receive a notification
                                       e.g. when the actor finished or failed. Note: if you already have a webhook set up for the actor or task,
                                       you do not have to add it again here.
            wait_secs (int, optional): The maximum number of seconds the server waits for the task run to finish. If not provided, waits indefinitely.

        Returns:
            dict: The run object
        r%   r   r&   r'   r(   rP   idrg   re   root_clientrunrO   	r6   r%   r   r&   r'   r(   rP   rg   started_runs	            r)   r`   zTaskClient.call   sW    D jj!'% ! 
 ##K$56FFQZF[[r+   c                    	 | j                   j                  | j                  d      d| j                               }t	        t
        |j                               S # t        $ r}t        |       Y d}~yd}~ww xY wzRetrieve the default input for this task.

        https://docs.apify.com/api/v2#/reference/actor-tasks/task-input-object/get-task-input

        Returns:
            dict, optional: Retrieved task input
        r!   GET)rX   rY   r\   N	r_   r`   ra   r^   r   dictr[   r   r   r6   rd   excs      r)   	get_inputzTaskClient.get_input   sm    	*'',,IIg&||~ - H
 hmmo.. 	*$S))	*s   AA 	A9$A44A9c                   | j                   j                  | j                  d      d| j                         |      }t	        t
        |j                               S )Update the default input for this task.

        https://docs.apify.com/api/v2#/reference/actor-tasks/task-input-object/update-task-input

        Returns:
            dict, Retrieved task input
        r!   PUTrX   rY   r\   r[   r_   r`   ra   r^   r   rv   r[   r6   r%   rd   s      r)   update_inputzTaskClient.update_input   sO     ##((		'"<<>	 ) 
 D(--/**r+   c                8    t        di | j                  d      S z,Retrieve a client for the runs of this task.rV   )r/   r#   )r   _sub_resource_init_optionsr?   s    r)   rV   zTaskClient.runs   s    "[T%D%DSY%D%Z[[r+   statusoriginc                   t        di | j                  dd| j                  t        |      t        |                  S )a  Retrieve the client for the last run of this task.

        Last run is retrieved based on the start time of the runs.

        Args:
            status (ActorJobStatus, optional): Consider only runs with this status.
            origin (MetaOrigin, optional): Consider only runs started with this origin.

        Returns:
            RunClient: The resource client for the last run of this task.
        lastrV   r   resource_idr/   r\   r#   )r   r   r^   r	   r6   r   r   s      r)   last_runzTaskClient.last_run  sP      	
--"$||:6B:6B $  . 	
 		
r+   c                4    t        di | j                         S z9Retrieve a client for webhooks associated with this task.r#   )r   r   r?   s    r)   rP   zTaskClient.webhooks  s    &K)H)H)JKKr+   )r6   r-   r7   r   r8   r   returnNone)r6   r-   r   dict | None)r6   r-   r   
str | Noner%   r   r   r   r&   
int | Noner'   r   r(   r   r"   r   r   rv   )r6   r-   r   r   )r6   r-   r%   r   r   r   r&   r   r'   r   r(   r   rO   r   rP   list[dict] | Noner   rv   )r6   r-   r%   r   r   r   r&   r   r'   r   r(   r   rP   r   rg   r   r   r   )r6   r-   r%   rv   r   rv   )r6   r-   r   r   )r6   r-   r   ActorJobStatus | Noner   MetaOrigin | Noner   r   )r6   r-   r   r   __name__
__module____qualname____doc__r   r4   r@   rH   rM   re   r`   ry   r   rV   r   rP   __classcell__r9   s   @r)   r-   r-   0   s   4G G
  "&  $$(#' (U(U (U  	(U
 (U (U "(U !(U (U 
(UT #'  $$(#'&*&*7>7>  7> 	7>
 7> "7> !7> $7> $7> 
7>x #'  $$(#'&* $+\+\  +\ 	+\
 +\ "+\ !+\ $+\ +\ 
+\Z&+ \ GKhl 
.Lr+   r-   c                  "    e Zd ZdZed fd       ZddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	dddddddd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
ddZddZddZdddddZddZ xZS )TaskClientAsyncz0Async sub-client for manipulating a single task.c                L    |j                  dd      }t        |   |d|i| y)zInitialize the TaskClientAsync.r/   r0   Nr1   r5   s       r)   r4   zTaskClientAsync.__init__   r:   r+   c                >   K   | j                          d{   S 7 w)r<   Nr=   r?   s    r)   r@   zTaskClientAsync.get&  s      YY[      NrA   c          	     v   K   t        |||||||      }| j                  t        |             d{   S 7 w)rC   rA   NrD   rF   s	            r)   rH   zTaskClientAsync.update0  sF     < 6!'%
 \\"DEX"YZZZZs   0979c                >   K   | j                          d{   S 7 w)rJ   NrK   r?   s    r)   rM   zTaskClientAsync.deleteZ  s     
 \\^###r   rN   c          
       K   | j                  ||||||t        |      nd      }| j                  j                  | j	                  d      dddi||       d{   }	t        t        |	j                                     S 7 &wrR   r]   rb   s
             r)   re   zTaskClientAsync.starta  s     L   )@H@T28<Z^ & 
 ))..		&!#%FG! / 
 
 !HMMO!<==
s   ABB'Brf   c                  K   | j                  ||||||       d{   }| j                  j                  |d         j                  |       d{   S 7 :7 w)ri   rj   Nrk   rl   rm   rp   s	            r)   r`   zTaskClientAsync.call  so     D !JJ!'% ' 
 
 %%))+d*;<LLW`Laaa
 bs!   AA5AAAAc                  K   	 | j                   j                  | j                  d      d| j                                d{   }t	        t
        |j                               S 7 "# t        $ r}t        |       Y d}~yd}~ww xY wwrs   ru   rw   s      r)   ry   zTaskClientAsync.get_input  s|     	*!--22IIg&||~ 3  H
 hmmo..  	*$S))	*s@   B>A' A%!A' $B%A' '	B0B ;B BBc                  K   | j                   j                  | j                  d      d| j                         |       d{   }t	        t
        |j                               S 7 "w)r{   r!   r|   r}   Nr~   r   s      r)   r   zTaskClientAsync.update_input  s]      ))..		'"<<>	 / 
 
 D(--/**
s   A A'A%#A'c                8    t        di | j                  d      S r   )r   r   r?   s    r)   rV   zTaskClientAsync.runs  s    '`$*I*IX^*I*_``r+   r   c                   t        di | j                  dd| j                  t        |      t        |                  S )a  Retrieve the client for the last run of this task.

        Last run is retrieved based on the start time of the runs.

        Args:
            status (ActorJobStatus, optional): Consider only runs with this status.
            origin (MetaOrigin, optional): Consider only runs started with this origin.

        Returns:
            RunClientAsync: The resource client for the last run of this task.
        r   rV   r   r   r#   )r   r   r^   r	   r   s      r)   r   zTaskClientAsync.last_run  sP      	
--"$||:6B:6B $  . 	
 		
r+   c                4    t        di | j                         S r   )r   r   r?   s    r)   rP   zTaskClientAsync.webhooks  s    +Pd.M.M.OPPr+   )r6   r   r7   r   r8   r   r   r   )r6   r   r   r   )r6   r   r   r   r%   r   r   r   r&   r   r'   r   r(   r   r"   r   r   rv   )r6   r   r   r   )r6   r   r%   r   r   r   r&   r   r'   r   r(   r   rO   r   rP   r   r   rv   )r6   r   r%   r   r   r   r&   r   r'   r   r(   r   rP   r   rg   r   r   r   )r6   r   r%   rv   r   rv   )r6   r   r   r   )r6   r   r   r   r   r   r   r   )r6   r   r   r   r   r   s   @r)   r   r     s   :G G
!  "&  $$(#' ([([ ([  	([
 ([ ([ "([ !([ ([ 
([T$ #'  $$(#'&*&*7>7>  7> 	7>
 7> "7> !7> $7> $7> 
7>x #'  $$(#'&* $+b+b  +b 	+b
 +b "+b !+b $+b +b 
+bZ&+ a LPmq 
.Qr+   r   )NNNNNNNN)r$   r   r   r   r%   r   r   r   r&   r   r'   r   r(   r   r"   r   r   rv   )#
__future__r   typingr   r   r   apify_shared.utilsr   r   r	   r
   apify_client._errorsr   apify_client._utilsr   r   r   apify_client.clients.baser   r   )apify_client.clients.resource_clients.runr   r   4apify_client.clients.resource_clients.run_collectionr   r   8apify_client.clients.resource_clients.webhook_collectionr   r   apify_shared.constsr   r   r*   r-   r   r#   r+   r)   <module>r      s    " + +  / c c I O n z>  "  $#
  	
     
2jL jLZjQ) jQr+   