o
    i+                     @   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)selfZ	schedulerr   r   	__class__r   F/home/app/Keep/.python/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   Z
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   Zreschedule_jobr   r   )r$   r   Z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   Z	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   Z
resume_jobr   r   r,   r   r   r'   resumek   r.   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   Z
remove_jobr   r   r,   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   r,   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   Zget_next_fire_time)r$   nowZ	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 rd|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 rt||d	< t|tst|tstd
t|tst|tstdt||| ||d< ||d< ||d< ||d< d	|v r| d	}|rt|tstd||d	< d|v r| d}|durt|tr|dkrt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(   Z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   r=   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 )NrK   rJ   zJob has version z#, but only version 1 can be handledr   r   r   r   r   r   r   r   r   r   r   )r?   r=   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)r9   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   r,   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: pausedr1   z (trigger: r7   ))r<   r   r   r   r   )r$   statusr   r   r'   __str__C  s   
zJob.__str__rQ   )rB   
__module____qualname____doc__	__slots__r!   r)   r*   r-   r/   r0   propertyr1   r6   r"   rN   rP   rT   rU   rY   __classcell__r   r   r%   r'   r      s$    	
g$r   N)collections.abcr   r   datetimer   inspectr   r   uuidr   Zapscheduler.triggers.baser   Zapscheduler.utilr	   r
   r   r   r   r   utcr3   r   r   r   r   r'   <module>   s     	