2012-08-15 14 views
6

C'è un modo per dire a celerybeat di modificare le impostazioni per un'attività specifica mentre è in esecuzione?Modifica dinamica delle impostazioni del beat di sedano

L'utilità di questo è meglio illustrato in questo esempio:

Ho un task periodico che controlla un valore ogni 30 secondi. A volte, in base a un trigger esterno (che non posso prevedere), desidero che questa attività aumenti la frequenza di polling a 10 secondi, per alcuni minuti.

È fattibile in modo gestibile? So di poter cambiare la configurazione compito e ricaricare il sedano ma che sembra un modo disordinato di fare le cose ...

+0

Hai trovato un modo? –

+1

@ CésarBustíos non proprio. Finì per costruire uno scheduler in-house sopra il sedano. Penso che sia più un uso previsto della biblioteca. – Goro

risposta

3

Sull'unità schedules.py troverete questo:

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 

Quindi, è possibile ignorare il metodo is_due per impostare il proprio timedelta.

+0

avendo problemi con questo. quando torno (True, 10) continua a ripetere l'attività in meno di un secondo. sembra un problema datetime – dtc

Problemi correlati