2012-08-15 2 views
6

셀러 비트가 실행 중일 때 특정 작업에 대한 설정을 변경하도록 지시하는 방법이 있습니까? 셀레 리 비트 설정을 동적으로 변경하는 방법

이러한 유틸리티

가장이 예에 도시되어

는 I 값이 30 초마다 주기적 검사 작업을 갖는다. 때로는 (예측할 수없는) 외부 방아쇠에 따라이 작업으로 폴링 빈도를 10 초로 늘리는 것이 좋습니다. 몇 분 동안.

관리 가능한 방식으로이 작업을 수행 할 수 있습니까? 나는 당신이 찾을 수 schedules.py 모듈에

+0

방법을 찾았습니까? –

+1

@ CésarBustíos 정말 아닙니다. 셀러리 위에 집안의 스케줄러를 구축했습니다. 나는 이것이 도서관의 의도 된 용도 이상의 것이라고 생각합니다. – Goro

답변

3

... 내가 작업 설정을 변경하고 셀러리를 다시로드하지만 그 일을 할 수있는 지저분한 방법을 보인다 수 있습니다 알고

class schedule(object): 

    def is_due(self, last_run_at): 
     """Returns tuple of two items `(is_due, next_time_to_run)`, 
     where next time to run is in seconds. 

     e.g. 

     * `(True, 20)`, means the task should be run now, and the next 
      time to run is in 20 seconds. 

     * `(False, 12)`, means the task should be run in 12 seconds. 

     You can override this to decide the interval at runtime, 
     but keep in mind the value of :setting:`CELERYBEAT_MAX_LOOP_INTERVAL`, 
     which decides the maximum number of seconds celerybeat can sleep 
     between re-checking the periodic task intervals. So if you 
     dynamically change the next run at value, and the max interval is 
     set to 5 minutes, it will take 5 minutes for the change to take 
     effect, so you may consider lowering the value of 
     :setting:`CELERYBEAT_MAX_LOOP_INTERVAL` if responsiveness is of 
     importance to you. 

     .. admonition:: Scheduler max interval variance 

     The default max loop interval may vary for different schedulers. 
     For the default scheduler the value is 5 minutes, but for e.g. 
     the django-celery database scheduler the value is 5 seconds. 

     """ 
     last_run_at = self.maybe_make_aware(last_run_at) 
     rem_delta = self.remaining_estimate(last_run_at) 
     rem = timedelta_seconds(rem_delta) 
     if rem == 0: 
      return True, self.seconds 
     return False, rem 

그래서, 당신은 대체 할 수 있습니다 자신의 timedelta를 설정하는 is_due 메소드.

+0

에 문제가 있습니다. 내가 돌아 왔을 때 (True, 10) 단지 1 초도 안되게 작업을 다시 실행합니다. 날짜 시간 문제와 같은 느낌 – dtc

관련 문제