o
    Fi+                     @   sj   d dl mZ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 G dd dZdS )	    )IterableMapping)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.
    )
_scheduler_jobstore_aliasidtriggerexecutorfuncfunc_refargskwargsnamemisfire_grace_timecoalescemax_instancesnext_run_time__weakref__Nc                    s6   t    || _d | _| jdd|pt ji| d S )Nr    )super__init__r   r   _modifyr   hex)self	schedulerr   r   	__class__r   P/var/www/html/humari/django-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'   modify@   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'   
rescheduleN   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   r0   r   r   r'   resumeh   r2   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   r0   r   r   r'   removet   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   r0   r   r   r'   pending}   s   
zJob.pendingc                 C   s>   g }| j }|r||kr|| | j||}|r||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   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 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   timezone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   rC   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 )NrS   rR   zJob has version z#, but only version 1 can be handledr   r   r   r   r   r   r   r   r   r   r   )rE   rC   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)r?   r   r   NotImplemented)r#   otherr   r   r'   __eq__8  s   
z
Job.__eq__c                 C   s   d| j  d| j dS )Nz	<Job (id=z name=z)>)r   r   r0   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: pausedr7   z (trigger: r=   ))rB   r   r
   r   r   )r#   statusr   r   r'   __str__@  s   
zJob.__str__rY   )rH   
__module____qualname____doc__	__slots__r    r*   r-   r1   r4   r6   propertyr7   r<   r!   rV   rX   r\   r]   ra   __classcell__r   r   r%   r'   r      s$    	
g$r   N)collections.abcr   r   inspectr   r   uuidr   apscheduler.triggers.baser   apscheduler.utilr   r	   r
   r   r   r   r   r   r   r   r'   <module>   s     
