o
    óT·jã+  ã                   @   s|   d dl mZmZ d dlmZ d dlmZm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 ejZG dd„ dƒZd	S )
é    )ÚIterableÚMapping)Útimezone)ÚisclassÚismethod)Úuuid4)ÚBaseTrigger)Úcheck_callable_argsÚconvert_to_datetimeÚdatetime_reprÚget_callable_nameÚ
obj_to_refÚ
ref_to_objc                       s’   e Zd ZdZdZd ‡ fdd„	Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
edd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )!ÚJobaË  
    Contains the options given when scheduling callables and its current schedule and other state.
    This class should never be instantiated by the user.

    :var str id: the unique identifier of this job
    :var str name: the description of this job
    :var func: the callable to execute
    :var tuple|list args: positional arguments to the callable
    :var dict kwargs: keyword arguments to the callable
    :var bool coalesce: whether to only run the job once when several run times are due
    :var trigger: the trigger object that controls the schedule of this job
    :var str executor: the name of the executor that will run this job
    :var int misfire_grace_time: the time (in seconds) how much this job's execution is allowed to
        be late (``None`` means "allow the job to run no matter how late it is")
    :var int max_instances: the maximum number of concurrently executing instances allowed for this
        job
    :var datetime.datetime next_run_time: the next scheduled run time of this job

    .. note::
        The ``misfire_grace_time`` has some non-obvious effects on job execution. See the
        :ref:`missed-job-executions` section in the documentation for an in-depth explanation.
    )Ú__weakref__Ú_jobstore_aliasÚ
_schedulerÚargsÚcoalesceÚexecutorÚfuncÚfunc_refÚidÚkwargsÚmax_instancesÚmisfire_grace_timeÚnameÚnext_run_timeÚtriggerNc                    s6   t ƒ  ¡  || _d | _| jdd|ptƒ ji|¤Ž d S )Nr   © )ÚsuperÚ__init__r   r   Ú_modifyr   Úhex)ÚselfÚ	schedulerr   r   ©Ú	__class__r   úR/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/apscheduler/job.pyr!   =   s   
 zJob.__init__c                 K   s   | j j| j| jfi |¤Ž | S )a-  
        Makes the given changes to this job and saves it in the associated job store.

        Accepted keyword arguments are the same as the variables on this class.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.modify_job`

        :return Job: this job instance

        )r   Ú
modify_jobr   r   )r$   Úchangesr   r   r(   ÚmodifyC   s   z
Job.modifyc                 K   s    | j j| j| j|fi |¤Ž | S )zÂ
        Shortcut for switching the trigger on this job.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.reschedule_job`

        :return Job: this job instance

        )r   Úreschedule_jobr   r   )r$   r   Útrigger_argsr   r   r(   Ú
rescheduleQ   s   	
ÿÿzJob.reschedulec                 C   ó   | j  | j| j¡ | S )z¼
        Temporarily suspend the execution of this job.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.pause_job`

        :return Job: this job instance

        )r   Ú	pause_jobr   r   ©r$   r   r   r(   Úpause_   ó   	z	Job.pausec                 C   r/   )zÄ
        Resume the schedule of this job if previously paused.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.resume_job`

        :return Job: this job instance

        )r   Ú
resume_jobr   r   r1   r   r   r(   Úresumek   r3   z
Job.resumec                 C   s   | j  | j| j¡ dS )z©
        Unschedules this job and removes it from its associated job store.

        .. seealso:: :meth:`~apscheduler.schedulers.base.BaseScheduler.remove_job`

        N)r   Ú
remove_jobr   r   r1   r   r   r(   Úremovew   s   z
Job.removec                 C   s
   | j du S )z{
        Returns ``True`` if the referenced job is still waiting to be added to its designated job
        store.

        N)r   r1   r   r   r(   Úpending€   s   
zJob.pendingc                 C   sV   g }| j }|r)| t¡| t¡kr)| |¡ | j ||¡}|r)| t¡| t¡ks|S )z´
        Computes the scheduled run times between ``next_run_time`` and ``now`` (inclusive).

        :type now: datetime.datetime
        :rtype: list[datetime.datetime]

        )r   Ú
astimezoneÚUTCÚappendr   Úget_next_fire_time)r$   ÚnowÚ	run_timesr   r   r   r(   Ú_get_run_times�   s   
þzJob._get_run_timesc           
      K   s  i }d|v r!|  d¡}t|tƒstdƒ‚t| dƒrtdƒ‚||d< d|v s-d|v s-d|v r¼d|v r6|  d¡n| j}d|v rB|  d¡n| j}d|v rN|  d¡n| j}t|tƒr]|}t	|ƒ}nt
|ƒrszt|ƒ}W n tyr   d}Y nw tdƒ‚t| d	ƒsŠ| d	d¡du rŠt|ƒ|d	< t|tƒs”t|tƒs˜td
ƒ‚t|tƒs¢t|tƒs¦tdƒ‚t|||ƒ ||d< ||d< ||d< ||d< d	|v rÔ|  d	¡}|rÌt|tƒsÐtdƒ‚||d	< d|v rò|  d¡}|durît|tƒrê|dkrîtdƒ‚||d< d|v �rt|  d¡ƒ}||d< d|v �r|  d¡}t|tƒ�r|dk�rtdƒ‚||d< d|v �r=|  d¡}t|tƒ�s9td|jj› d�ƒ‚||d< d|v �rU|  d¡}t|tƒ�sQtdƒ‚||d< d|v �ri|  d¡}t|| jjdƒ|d< |�rvtd d |¡¡ƒ‚| ¡ D ]\}	}t| |	|ƒ �qzdS )z|
        Validates the changes to the Job and makes the modifications if and only if all of them
        validate.

        r   zid must be a nonempty stringzThe job ID may not be changedr   r   r   Nz5func must be a callable or a textual reference to oner   z"args must be a non-string iterablez!kwargs must be a dict-like objectr   zname must be a nonempty stringr   r   z<misfire_grace_time must be either None or a positive integerr   r   z(max_instances must be a positive integerr   z!Expected a trigger instance, got z insteadr   zexecutor must be a stringr   z6The following are not modifiable attributes of Job: {}ú, )ÚpopÚ
isinstanceÚstrÚ	TypeErrorÚhasattrÚ
ValueErrorr   r   r   r   Úcallabler   Úgetr   r   r   r	   ÚintÚboolr   r'   Ú__name__r
   r   r   ÚAttributeErrorÚformatÚjoinÚitemsÚsetattr)
r$   r*   ÚapprovedÚvaluer   r   r   r   r   Úkeyr   r   r(   r"   �   sž   




þ

ÿ




ÿ




ÿÿÿÿzJob._modifyc                 C   sŠ   | j std| j›d�ƒ‚| j}t|ƒr)t|jƒs)t|ƒ| j kr)|jft| jƒ }n| j}d| j	| j | j
| j|| j| j| j| j| j| jdœS )NzCThis Job cannot be serialized since the reference to its callable (z^) could not be determined. Consider giving a textual reference (module:function name) instead.é   )Úversionr   r   r   r   r   r   r   r   r   r   r   )r   rF   r   r   r   Ú__self__r   Útupler   r   r   r   r   r   r   r   r   r   )r$   r   r   r   r   r(   Ú__getstate__  s2   ÿÿþôzJob.__getstate__c                 C   s¢   |  dd¡dkrtd|d › d�ƒ‚|d | _|d | _t| jƒ| _|d | _|d | _|d	 | _|d
 | _	|d | _
|d | _|d | _|d | _|d | _d S )NrU   rT   zJob has version z#, but only version 1 can be handledr   r   r   r   r   r   r   r   r   r   r   )rH   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   )r$   Ústater   r   r(   Ú__setstate__(  s    ÿ









zJob.__setstate__c                 C   s   t |tƒr| j|jkS tS ©N)rB   r   r   ÚNotImplemented)r$   Úotherr   r   r(   Ú__eq__;  s   
z
Job.__eq__c                 C   s   d| j › d| j› d�S )Nz	<Job (id=z name=z)>)r   r   r1   r   r   r(   Ú__repr__@  s   zJob.__repr__c                 C   sB   t | dƒr| jrdt| jƒ nd}nd}| j› d| j› d|› d�S )Nr   znext run at: Úpausedr8   z (trigger: r@   ú))rE   r   r   r   r   )r$   Ústatusr   r   r(   Ú__str__C  s   
ÿýzJob.__str__r[   )rK   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r!   r+   r.   r2   r5   r7   Úpropertyr8   r?   r"   rX   rZ   r^   r_   rc   Ú__classcell__r   r   r&   r(   r      s$    	
g$r   N)Úcollections.abcr   r   Údatetimer   Úinspectr   r   Úuuidr   Úapscheduler.triggers.baser   Úapscheduler.utilr	   r
   r   r   r   r   Úutcr:   r   r   r   r   r(   Ú<module>   s     	