2012-08-25 2 views
3

저는 파이썬 프로젝트를 위해 자바에서 석영과 같은 이벤트 스케줄러를 찾고 있습니다.Python : 이벤트 스케쥴러 (석영처럼)

내 요구 사항

1) 일부 구간

감사 후 사용자에게 이메일이나 SMS를 보내기 파이썬

나에게 좋은 스케줄러를 제안하십시오!

@celery.task 
def sendmail(from_addr, to_addrs, msg): 
    "send mail here" 

sendmail.apply_async(args, countdown=n) # send email in `n` seconds 

답변

1

celery는 작업에 대한 잔인한뿐만 아니라 quartz 수 있습니다.

from apscheduler.scheduler import Scheduler 

sched = Scheduler() 

@sched.interval_schedule(hours=3) 
def some_job(): 
    print "Decorated job" 

sched.configure(options_from_ini_file) 
sched.start() 
+0

@Sebastian 보내는 메일뿐만 아니라

은 예입니다 내 작업은 SMS를 보내는 것과 같을 수있다. – user1614526

1

사소한 솔루션은 다음과 같습니다 :

from aqcron import At 
from time import sleep 
from datetime import datetime 

# Event scheduling 
event_1 = At(second=5) 
event_2 = At(second=[0,20,40]) 

while True: 
    now = datetime.now() 

    # Event check 
    if now in event_1: print "event_1" 
    if now in event_2: print "event_2" 

    sleep(1) 

그리고 aqcron.At는 클래스 :

# aqcron.py 

class At(object): 
    def __init__(self, year=None, month=None, 
       day=None,  weekday=None, 
       hour=None, minute=None, 
       second=None): 
     loc = locals() 
     loc.pop("self") 
     self.at = dict((k, v) for k, v in loc.iteritems() if v != None) 

    def __contains__(self, now): 
     for k in self.at.keys(): 
      try: 
       if not getattr(now, k) in self.at[k]: return False 
      except TypeError: 
       if self.at[k] != getattr(now, k): return False 
     return True 
관련 문제