Module: Delayed::MessageSending
- Defined in:
- lib/delayed/message_sending.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #send_at(time, method, *args) ⇒ Object
- #send_at_with_queue(time, method, queue, *args) ⇒ Object
- #send_later(method, *args) ⇒ Object
- #send_later_enqueue_args(method, enqueue_args = {}, *args) ⇒ Object
- #send_later_if_production(*args) ⇒ Object
- #send_later_if_production_enqueue_args(method, enqueue_args, *args) ⇒ Object
- #send_later_unless_in_job(method, *args) ⇒ Object
- #send_later_with_queue(method, queue, *args) ⇒ Object
- #send_now_or_later(_when, *args) ⇒ Object
- #send_now_or_later_if_production(_when, *args) ⇒ Object
Instance Method Details
#send_at(time, method, *args) ⇒ Object
41 42 43 44 |
# File 'lib/delayed/message_sending.rb', line 41 def send_at(time, method, *args) send_later_enqueue_args(method, { :run_at => time }, *args) end |
#send_at_with_queue(time, method, queue, *args) ⇒ Object
46 47 48 49 50 |
# File 'lib/delayed/message_sending.rb', line 46 def send_at_with_queue(time, method, queue, *args) send_later_enqueue_args(method, { :run_at => time, :queue => queue }, *args) end |
#send_later(method, *args) ⇒ Object
3 4 5 |
# File 'lib/delayed/message_sending.rb', line 3 def send_later(method, *args) send_later_enqueue_args(method, {}, *args) end |
#send_later_enqueue_args(method, enqueue_args = {}, *args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/delayed/message_sending.rb', line 7 def send_later_enqueue_args(method, enqueue_args = {}, *args) enqueue_args = enqueue_args.dup # support procs/methods as enqueue arguments enqueue_args.each do |k,v| if v.respond_to?(:call) enqueue_args[k] = v.call(self) end end no_delay = enqueue_args.delete(:no_delay) if !no_delay # delay queuing up the job in another database until the results of the current # transaction are visible connection = self.class.connection if self.class.respond_to?(:connection) connection ||= self.connection if respond_to?(:connection) connection ||= ActiveRecord::Base.connection if (Delayed::Job != Delayed::Backend::ActiveRecord::Job || connection != Delayed::Job.connection) connection.after_transaction_commit do Delayed::Job.enqueue(Delayed::PerformableMethod.new(self, method.to_sym, args), enqueue_args) end return nil end end result = Delayed::Job.enqueue(Delayed::PerformableMethod.new(self, method.to_sym, args), enqueue_args) result = nil unless no_delay result end |
#send_later_if_production(*args) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/delayed/message_sending.rb', line 61 def send_later_if_production(*args) if Rails.env.production? send_later(*args) else send(*args) end end |
#send_later_if_production_enqueue_args(method, enqueue_args, *args) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/delayed/message_sending.rb', line 69 def send_later_if_production_enqueue_args(method, enqueue_args, *args) if Rails.env.production? send_later_enqueue_args(method, enqueue_args, *args) else send(method, *args) end end |
#send_later_unless_in_job(method, *args) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/delayed/message_sending.rb', line 52 def send_later_unless_in_job(method, *args) if Delayed::Job.in_delayed_job? send(method, *args) else send_later(method, *args) end nil # can't rely on the type of return value, so return nothing end |
#send_later_with_queue(method, queue, *args) ⇒ Object
37 38 39 |
# File 'lib/delayed/message_sending.rb', line 37 def send_later_with_queue(method, queue, *args) send_later_enqueue_args(method, { :queue => queue }, *args) end |
#send_now_or_later(_when, *args) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/delayed/message_sending.rb', line 77 def send_now_or_later(_when, *args) if _when == :now send(*args) else send_later(*args) end end |
#send_now_or_later_if_production(_when, *args) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/delayed/message_sending.rb', line 85 def send_now_or_later_if_production(_when, *args) if _when == :now send(*args) else send_later_if_production(*args) end end |