
NhP+                 @   s   d  d l  m Z m Z d  d l m Z d  d l Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z m Z m Z m Z m Z y d  d l m Z m Z Wn( e k
 r d  d l m Z m Z Yn XGd d   d e  Z d S)	    )ismethodisclass)uuid4N)BaseTrigger)
ref_to_obj
obj_to_refdatetime_reprrepr_escapeget_callable_namecheck_callable_argsconvert_to_datetime)IterableMappingc                   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 d- d.   Z   S)0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
    :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_timeNc                sH   t  t |   j   | |  _ d  |  _ |  j d | p= t   j |  d  S)Nr   )superr   __init__r   r   _modifyr   hex)selfZ	schedulerr   r   )	__class__ K/mod/web/acousticsspace/venv/lib/python3.5/site-packages/apscheduler/job.pyr   -   s    		zJob.__init__c             K   s    |  j  j |  j |  j |  |  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%   modify3   s    z
Job.modifyc             K   s#   |  j  j |  j |  j | |  |  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%   
rescheduleA   s    	zJob.reschedulec             C   s   |  j  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%   pauseM   s    	z	Job.pausec             C   s   |  j  j |  j |  j  |  S)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%   resumeY   s    	z
Job.resumec             C   s   |  j  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%   removee   s    z
Job.removec             C   s   |  j  d k 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%   pendingn   s    zJob.pendingc             C   sN   g  } |  j  } x8 | rI | | k rI | j |  |  j j | |  } q W| S)z
        Computes the scheduled run times between ``next_run_time`` and ``now`` (inclusive).

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

        )r   appendr   Zget_next_fire_time)r"   nowZ	run_timesr   r$   r$   r%   _get_run_times{   s    	zJob._get_run_timesc       
      K   sf  i  } d | k rd | j  d  } t | t j  s? t d   t |  d  rZ t d   | | d <d | k s d | k s d | k r-d | k r | j  d  n |  j } d | k r | j  d  n |  j } d | k r | j  d  n |  j	 } t | t j  r| } t
 |  } nF t |  rUy t |  } Wqat k
 rQd } YqaXn t d   t |  d	  r| j d	 d  d k rt |  | d	 <t | t j  st | t  rt d
   t | t j  st | t  rt d   t | | |  | | d <| | d <| | d <| | d <d	 | k rx| j  d	  } | sbt | t j  rnt d   | | d	 <d | k r| j  d  } | d k	 rt | t j  s| d k rt d   | | d <d | k rt | j  d   } | | d <d | k rO| j  d  } t | t j  s9| d k rEt d   | | d <d | k r| j  d  } t | t  st d | j j   | | d <d | k r| j  d  } t | t j  st d   | | d <d | k r| j  d  } t | |  j j d  | d <| r2t d d j |    x- t j |  D] \ }	 } t |  |	 |  qBWd 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 %s insteadr   zexecutor must be a stringr   z6The following are not modifiable attributes of Job: %sz, )pop
isinstancesixstring_types	TypeErrorhasattr
ValueErrorr   r   r   r   callabler   getr
   r   r   r   integer_typesboolr   r#   __name__r   r   timezoneAttributeErrorjoin	iteritems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 f   t |  j  r` t |  j j  r` |  j j f t |  j  } n	 |  j } d d d |  j d |  j  d |  j	 d |  j
 d | d	 |  j d
 |  j d |  j d |  j d |  j d |  j i S)NzThis Job cannot be serialized since the reference to its callable (%r) could not be determined. Consider giving a textual reference (module:function name) instead.version   r   r   r   r   r   r   r   r   r   r   r   )r   r6   r   r   r   __self__tupler   r   r   r   r   r   r   r   r   r   )r"   r   r$   r$   r%   __getstate__   s&    	"										zJob.__getstate__c             C   s   | j  d d  d k r, t d | d   | d |  _ | d |  _ t |  j  |  _ | d |  _ | d |  _ | d |  _ | d	 |  _	 | d
 |  _
 | d |  _ | d |  _ | d |  _ | d |  _ d  S)NrC   rD   z5Job has version %s, but only version 1 can be handledr   r   r   r   r   r   r   r   r   r   r   )r8   r6   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 St S)N)r1   r   r   NotImplemented)r"   otherr$   r$   r%   __eq__  s    z
Job.__eq__c             C   s    d t  |  j  t  |  j  f S)Nz<Job (id=%s name=%s)>)r	   r   r   )r"   r$   r$   r%   __repr__   s    zJob.__repr__c             C   s   t  |  j    S)N)r	   __unicode__)r"   r$   r$   r%   __str__#  s    zJob.__str__c             C   sQ   t  |  d  r4 |  j r+ d t |  j  n d } n d } d |  j |  j | f S)Nr   znext run at: Zpausedr,   z%s (trigger: %s, %s))r5   r   r   r   r   )r"   statusr$   r$   r%   rN   &  s    %zJob.__unicode__)z
_schedulerz_jobstore_aliaszidztriggerzexecutorzfunczfunc_refzargszkwargsznamezmisfire_grace_timezcoalescezmax_instancesznext_run_time)r;   
__module____qualname____doc__	__slots__r   r'   r(   r)   r*   r+   propertyr,   r/   r    rG   rI   rL   rM   rO   rN   r$   r$   )r#   r%   r      s&     	`r   )inspectr   r   uuidr   r2   Zapscheduler.triggers.baser   Zapscheduler.utilr   r   r   r	   r
   r   r   collections.abcr   r   ImportErrorcollectionsobjectr   r$   r$   r$   r%   <module>   s   4