U
    Šfj«  ã                   @   sj   d dl mZmZ d dlZd dlZG dd„ deƒZG dd„ deƒZG dd„ deƒZ	G d	d
„ d
e 
e¡ƒZdS )é    )ÚABCMetaÚabstractmethodNc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚJobLookupErrorzBRaised when the job store cannot find a job for update or removal.c                    s   t t| ƒ d| ¡ d S )Nz No job by the id of %s was found)Úsuperr   Ú__init__©ÚselfZjob_id©Ú	__class__© ú>/tmp/pip-unpacked-wheel-3wcy9vrk/apscheduler/jobstores/base.pyr   
   s    zJobLookupError.__init__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r	   r   r      s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚConflictingIdErrorz8Raised when the uniqueness of job IDs is being violated.c                    s   t t| ƒ d| ¡ d S )Nz2Job identifier (%s) conflicts with an existing job)r   r   r   r   r	   r   r   r      s    
ÿzConflictingIdError.__init__r   r   r   r	   r   r      s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚTransientJobErrorzs
    Raised when an attempt to add transient (with no func_ref) job to a persistent job store is
    detected.
    c                    s   t t| ƒ d| ¡ d S )NzgJob (%s) cannot be added to this job store because a reference to the callable could not be determined.)r   r   r   r   r	   r   r   r      s
    
ÿÿzTransientJobError.__init__r   r   r   r	   r   r      s   r   c                   @   s¢   e Zd ZdZdZdZe d¡Zdd„ Z	dd„ Z
dd	„ Zed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ ZdS )ÚBaseJobStorezSAbstract base class that defines the interface that every job store must implement.Nzapscheduler.jobstoresc                 C   s    || _ || _t d| ¡| _dS )ax  
        Called by the scheduler when the scheduler is being started or when the job store is being
        added to an already running scheduler.

        :param apscheduler.schedulers.base.BaseScheduler scheduler: the scheduler that is starting
            this job store
        :param str|unicode alias: alias of this job store as it was assigned to the scheduler
        zapscheduler.jobstores.%sN)Ú
_schedulerÚ_aliasÚloggingÚ	getLoggerÚ_logger)r   Z	schedulerÚaliasr   r   r   Ústart)   s    
zBaseJobStore.startc                 C   s   dS )z2Frees any resources still bound to this job store.Nr   ©r   r   r   r   Úshutdown7   s    zBaseJobStore.shutdownc                 C   sL   t |ƒD ]>\}}|jd k	r|dkrB|d |… }|d |…= | |¡  qHqd S )Nr   )Ú	enumerateZnext_run_timeÚextend)r   ÚjobsÚiÚjobZpaused_jobsr   r   r   Ú_fix_paused_jobs_sorting:   s    


z%BaseJobStore._fix_paused_jobs_sortingc                 C   s   dS )aG  
        Returns a specific job, or ``None`` if it isn't found..

        The job store is responsible for setting the ``scheduler`` and ``jobstore`` attributes of
        the returned job to point to the scheduler and itself, respectively.

        :param str|unicode job_id: identifier of the job
        :rtype: Job
        Nr   r   r   r   r   Ú
lookup_jobC   s    zBaseJobStore.lookup_jobc                 C   s   dS )a  
        Returns the list of jobs that have ``next_run_time`` earlier or equal to ``now``.
        The returned jobs must be sorted by next run time (ascending).

        :param datetime.datetime now: the current (timezone aware) datetime
        :rtype: list[Job]
        Nr   )r   Únowr   r   r   Úget_due_jobsO   s    zBaseJobStore.get_due_jobsc                 C   s   dS )z­
        Returns the earliest run time of all the jobs stored in this job store, or ``None`` if
        there are no active jobs.

        :rtype: datetime.datetime
        Nr   r   r   r   r   Úget_next_run_timeY   s    zBaseJobStore.get_next_run_timec                 C   s   dS )a—  
        Returns a list of all jobs in this job store.
        The returned jobs should be sorted by next run time (ascending).
        Paused jobs (next_run_time == None) should be sorted last.

        The job store is responsible for setting the ``scheduler`` and ``jobstore`` attributes of
        the returned jobs to point to the scheduler and itself, respectively.

        :rtype: list[Job]
        Nr   r   r   r   r   Úget_all_jobsb   s    zBaseJobStore.get_all_jobsc                 C   s   dS )z¶
        Adds the given job to this store.

        :param Job job: the job to add
        :raises ConflictingIdError: if there is another job in this store with the same ID
        Nr   ©r   r#   r   r   r   Úadd_jobo   s    zBaseJobStore.add_jobc                 C   s   dS )z²
        Replaces the job in the store with the given newer version.

        :param Job job: the job to update
        :raises JobLookupError: if the job does not exist
        Nr   r*   r   r   r   Ú
update_jobx   s    zBaseJobStore.update_jobc                 C   s   dS )z¬
        Removes the given job from this store.

        :param str|unicode job_id: identifier of the job
        :raises JobLookupError: if the job does not exist
        Nr   r   r   r   r   Ú
remove_job�   s    zBaseJobStore.remove_jobc                 C   s   dS )z!Removes all jobs from this store.Nr   r   r   r   r   Úremove_all_jobsŠ   s    zBaseJobStore.remove_all_jobsc                 C   s   d| j j S )Nz<%s>)r
   r   r   r   r   r   Ú__repr__Ž   s    zBaseJobStore.__repr__)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   r   "   s0   
	

	





r   )Úabcr   r   r   ÚsixÚKeyErrorr   r   Ú
ValueErrorr   Úwith_metaclassr   r   r   r   r   Ú<module>   s   