o ckF[}@sxddlZddlmZmZmZddlmZddlZddlZddl Z ddl m Z ddZ GdddeZ Gd d d eZdS) N)StringPropertyDateTimePropertyIntegerProperty)Model)StringIOcCs,|dkrdSt|dkst|dkrtdS)N*r)int ValueError)valr 2/usr/lib/python3/dist-packages/boto/manage/task.py check_hours rcseZdZdZeZededdZeddZe Z e Z eZ eZeddZdfd d Zd d Zd dZdddZddZZS)Taska A scheduled, repeating task that can be executed by any participating servers. The scheduling is similar to cron jobs. Each task has an hour attribute. The allowable values for hour are [0-23|*]. To keep the operation reasonably efficient and not cause excessive polling, the minimum granularity of a Task is hourly. Some examples: hour='*' - the task would be executed each hour hour='3' - the task would be executed at 3AM GMT each day. Tr)required validatordefault)rcCs|D]}||qdSN)allstart)cls queue_nametaskr r r start_all9s  zTask.start_allNc s@tt|j|fi||jdk|_|jdk|_tj|_dS)Nr) superr__init__hourhourlydailydatetimeutcnownow)selfidkw __class__r r r>s  z Task.__init__cCstjd|j|j|jf|jr|jsdS|jr>|js>t|j |jj kr'dSt t|j |jj |jj t|j ddS|j|j}|jrS|j dkrNdSd|j St|j |jj kre|j dkrcdSdSt t|j |jj |jj t|j ddS)ag Determine how long until the next scheduled time for a Task. Returns the number of seconds until the next scheduled time or zero if the task needs to be run immediately. If it's an hourly task and it's never been run, run it now. If it's a daily task and it's never been run and the hour is right, run it now. z!checking Task[%s]-now=%s, last=%sr<iipC) botologinfonamer! last_executedrrr rmaxsecondsdays)r"deltar r r checkDs"  .    .z Task.checkcCstjd|j|jft}tj|jdtjtjtjd}d}|}| durZtjd||f||krK||7}tjd|j|f|rK| |t d|d7}| dus'| }||d||dtjd |j|f|j|_|j|_|dd |_dS) NzTask[%s] - running:%sT)shellstdinstdoutstderrznsecs=%s, timeout=%sz(Task[%s] - setting timeout to %d secondsrr(zTask[%s] - output: %si)r)r*r+r,commandr subprocessPopenPIPEpollchange_visibilitytimesleep communicatewritegetvaluer!r- returncode last_status last_output)r"msgvtimeoutlog_fpprocessnsecscurrent_timeouttr r r _runfs0     z Task._runr'cCs|}tjd|j|f|dkrM||||j}||j}| |}|j|_ | tjd|j|jf| tjd|j|jfdStjd|| |dS)NzTask[%s] - delay=%s secondsrzTask[%s] - new message id=%szTask[%s] - deleted message %sznew_vtimeout: %d)r2r)r*r+r,rMqueue new_messager#rA message_idputdeleter=)r"rFrGdelayrNnew_msgr r r run~s   zTask.runcCs^tjd|j|ftd|}||j}||}|j|_| tjd|jdS)Nz"Task[%s] - starting with queue: %ssqszTask[%s] - start successful) r)r*r+r,lookuprOr#rArPrQ)r"rrNrFr r r rs   z Task.startr)r')__name__ __module__ __qualname____doc__rr,rrr8rr-rrDrErP classmethodrrr2rMrUr __classcell__r r r%r r#s    " rc@seZdZddZdddZdS) TaskPollercCst|_|j||_dSr)r) connect_sqsrVrWrN)r"rr r r rs zTaskPoller.__init__r'cCs| |j|}|r8t|}|r7|jr|j|jkr.tj d|j |jf| ||ntj d|j nt |q)NTzTask[%s] - read message %sz-Task[%s] - found extraneous message, ignoring)rNreadr get_by_idget_bodyrPr#r)r*r+r,rUr>r?)r"waitrGmrr r r r<s  zTaskPoller.pollN)r'r')rXrYrZrr<r r r r r^sr^)r)boto.sdb.db.propertyrrrboto.sdb.db.modelrrr9r> boto.compatrrrobjectr^r r r r s  u