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