2012-08-15 23 views
6

Czy jest jakiś sposób, aby powiedzieć celerybeat, aby zmienić ustawienia dla określonego zadania podczas jego działania?Dynamiczne zmienianie ustawień rytmu selera

Narzędzie to jest najlepiej zilustrowana w poniższym przykładzie:

mam okresowe zadania, który sprawdza wartości co 30 sekund. Czasami, w oparciu o zewnętrzny wyzwalacz (którego nie mogę przewidzieć), będę chciał, aby to zadanie zwiększyło częstotliwość odpytywania do 10 s - na kilka minut.

Czy to wykonalne w łatwy do opanowania sposób? Wiem, że mogę zmienić config zadania i przeładować seler ale wydaje niechlujny sposób, aby robić rzeczy ...

+0

Czy znalazłeś sposób? –

+1

@ CésarBustíos niezupełnie. Skończyło się budowanie harmonogramu w domu na szczycie selera. Myślę, że to bardziej zamierzone wykorzystanie biblioteki. – Goro

Odpowiedz

3

Na module schedules.py znajdziesz to:

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 

Tak, można zastąpić metoda is_due, aby ustawić własną timedelta.

+0

mając problemy z tym. kiedy wrócę (prawda, 10), po prostu ponownie uruchamia zadanie w mniej niż sekundę. czuje się jak problem datetime – dtc

Powiązane problemy