HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/tempora/__pycache__/schedule.cpython-310.pyc
o

;jv�@s�dZddlZddlZddlZddlZddlZdd�Zdd�ZGdd�dej�ZGd	d
�d
e�Z	Gdd�de	�Z
Gd
d�d�ZGdd�de�ZGdd�de�Z
dS)a�
Classes for calling functions a schedule. Has time zone support.

For example, to run a job at 08:00 every morning in 'Asia/Calcutta':

>>> job = lambda: print("time is now", datetime.datetime())
>>> time = datetime.time(8, tzinfo=pytz.timezone('Asia/Calcutta'))
>>> cmd = PeriodicCommandFixedDelay.daily_at(time, job)
>>> sched = InvokeScheduler()
>>> sched.add(cmd)
>>> while True:  # doctest: +SKIP
...     sched.run_pending()
...     time.sleep(.1)
�NcCstj�tj�S)u�
    Provide the current timezone-aware datetime.

    A client may override this function to change the default behavior,
    such as to use local time or timezone-naïve times.
    )�datetime�now�pytz�utc�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/tempora/schedule.pyrsrcCstj�|tj�S)u�
    Convert a numeric timestamp to a timezone-aware datetime.

    A client may override this function to change the default behavior,
    such as to use local time or timezone-naïve times.
    )r�
fromtimestamprr)�tsrrr�from_timestamp"sr
c@sHeZdZdZedd��Zedd��Zedd��Zedd	��Z	d
d�Z
dS)
�DelayedCommandzK
    A command to be executed after some delay (seconds or timedelta).
    c	Cs&||j|j|j|j|j|j|j|j�S�N)�year�month�day�hour�minute�second�microsecond�tzinfo)�cls�otherrrr�
from_datetime1s�zDelayedCommand.from_datetimecCs<t|tj�stj|d�}t�|}|�|�}||_||_|S)N��seconds)�
isinstancer�	timedeltarr�delay�target)rrrZdue_time�cmdrrr�after>s

zDelayedCommand.aftercCst|tj�s|St|�S)z�
        If input is a real number, interpret it as a Unix timestamp
        (seconds sinc Epoch in UTC) and return a timezone-aware
        datetime object. Otherwise return input unchanged.
        )r�numbersZRealr
)�inputrrr�_from_timestampHszDelayedCommand._from_timestampcCs*|�|�}|�|�}|t�|_||_|S)zt
        Construct a DelayedCommand to come due at `at`, where `at` may be
        a datetime or timestamp.
        )r"rrrr)r�atrrrrr�at_timeSs


zDelayedCommand.at_timecCs
t�|kSr)r��selfrrr�due_�
zDelayedCommand.dueN)�__name__�
__module__�__qualname__�__doc__�classmethodrr�staticmethodr"r$r'rrrrr,s

	


rcs<eZdZdZdd�Zedd��Zdd�Z�fdd	�Z�Z	S)
�PeriodicCommandzY
    Like a delayed command, but expect this command to run every delay
    seconds.
    cCs|�||j�S)z.
        Add delay to self, localized
        )�	_localizerr%rrr�
_next_timeiszPeriodicCommand._next_timecCs2z
|j}|�|jdd��WSty|YSw)zH
        Rely on pytz.localize to ensure new result honors DST.
        N)r)r�localize�replace�AttributeError)�dt�tzrrrr0os�zPeriodicCommand._localizecCs$|j�|���}|j|_|j|_|Sr)�	__class__rr1rr)r&rrrr�nextzszPeriodicCommand.nextcs.|dkr|t��kstd��t��||�dS)Nrz7A PeriodicCommand must have a positive, non-zero delay.)rr�
ValueError�super�__setattr__)r&�key�value�r7rrr;�s
�zPeriodicCommand.__setattr__)
r)r*r+r,r1r.r0r8r;�
__classcell__rrr>rr/cs

r/c@s(eZdZdZedd��Zedd��ZdS)�PeriodicCommandFixedDelayz�
    Like a periodic command, but don't calculate the delay based on
    the current time. Instead use a fixed delay following the initial
    run.
    cCs<|�|�}|�|�}t|tj�rtj|d�}||_||_|S)z}
        >>> cmd = PeriodicCommandFixedDelay.at_time(0, 30, None)
        >>> cmd.delay.total_seconds()
        30.0
        r)	r"rrr �Numberrrrr)rr#rrrrrrr$�s

z!PeriodicCommandFixedDelay.at_timecCsXtjdd�}tj�tj��|�}||8}|t�kr"||7}|t�ks|�|�|�||�S)a
        Schedule a command to run at a specific time each day.

        >>> from tempora import utc
        >>> noon = utc.time(12, 0)
        >>> cmd = PeriodicCommandFixedDelay.daily_at(noon, None)
        >>> cmd.delay.total_seconds()
        86400.0
        �)�days)rr�combine�date�todayrr$r0)rr#rZdailyZwhenrrr�daily_at�s

�z"PeriodicCommandFixedDelay.daily_atN)r)r*r+r,r-r$rGrrrrr@�s
r@c@s6eZdZdZdd�Zdd�Zdd�Zejdd	��Z	d
S)�	Schedulerzj
    A rudimentary abstract scheduler accepting DelayedCommands
    and dispatching them on schedule.
    cCs
g|_dSr)�queuer%rrr�__init__�r(zScheduler.__init__cCs t|t�sJ�t�|j|�dSr)rr�bisect�insortrI�r&Zcommandrrr�add�sz
Scheduler.addcCsT|jr(|jd}|��sdS|�|�t|t�r|�|���|jd=|jsdSdS)Nr)rIr'�runrr/rNr8rMrrr�run_pending�s


�zScheduler.run_pendingcCsdS)z!
        Run the command
        NrrMrrrrO�sz
Scheduler.runN)
r)r*r+r,rJrNrP�abc�abstractmethodrOrrrrrH�s
rHc@seZdZdZdd�ZdS)�InvokeSchedulerzB
    Command targets are functions to be invoked on schedule.
    cCs|��dSr)rrMrrrrO�szInvokeScheduler.runN)r)r*r+r,rOrrrrrS�srScs(eZdZdZ�fdd�Zdd�Z�ZS)�CallbackSchedulerzH
    Command targets are passed to a dispatch callable on schedule.
    cst���||_dSr)r:rJ�dispatch)r&rUr>rrrJ�s

zCallbackScheduler.__init__cCs|�|j�dSr)rUrrMrrrrO�szCallbackScheduler.run)r)r*r+r,rJrOr?rrr>rrT�srT)r,rr rQrKrrr
rr/r@rHrSrTrrrr�<module>s

7%*