2016-08-09 11 views
1

私は、あるデバイスが特定の所定の時間に操作される、Railsベースのインターネット・オブ・フィールズ(IOT)プラットフォームの構築に取り組んでいます。しかし、Herokuの組み込みスケジューリングライブラリは一定の間隔でコールバックをサポートするだけなので、特定の時間にアクションを実行するのは難しいです。私のサーバーは、将来の繰り返しなしに任意の時間に呼び出しを行う必要があります。この機能を果たすことができる他の宝石や方法がありますか?特定の時間にアクションを実行する方法 - Rails Herokuサーバー?

答えて

0

delyed job gemを使用できます。特定の時刻にタスクを実行するには、run_atフィールドを使用します。
ここに例があります

class LongTasks 
    def send_mailer 
    # Some other code 
    end 
    handle_asynchronously :send_mailer, :priority => 20 

    def in_the_future 
    # Some other code 
    end 
    # 5.minutes.from_now will be evaluated when in_the_future is called 
    handle_asynchronously :in_the_future, :run_at => Proc.new { 5.minutes.from_now } 

    def self.when_to_run 
    2.hours.from_now 
    end 

    class << self 
    def call_a_class_method 
     # Some other code 
    end 
    handle_asynchronously :call_a_class_method, :run_at => Proc.new { when_to_run } 
    end 

    attr_reader :how_important 

    def call_an_instance_method 
    # Some other code 
    end 
    handle_asynchronously :call_an_instance_method, :priority => Proc.new {|i| i.how_important } 
end 
関連する問題