2012-08-15 6 views
6

実行中に特定のタスクの設定を変更するようセロリビートに指示する方法はありますか?セロリビート設定を動的に変更する

これの有用性は、最もよくこの例で説明します。

私は値を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)、ちょうど2秒以内にタスクを再実行し続けます。日時の問題のように感じる – dtc

関連する問題