Module: Rage::Deferred
- Defined in:
- lib/rage/deferred/deferred.rb
Overview
Rage::Deferred
is an in-process background task queue with at-least-once delivery guarantee that allows you to schedule tasks to be executed later. It can be used to offload long-running operations, such as sending emails or communicating with external APIs.
To schedule a task, first define a task class that includes Rage::Deferred::Task
and implements the #perform
method.
class SendWelcomeEmail
include Rage::Deferred::Task
def perform(email)
# logic to send the welcome email
end
end
Then, push the task to the deferred queue:
SendWelcomeEmail.enqueue(email: user.email)
You can also specify a delay for the task execution using the delay
option:
SendWelcomeEmail.enqueue(email: user.email, delay: 10) # execute after 10 seconds
Or you can specify a specific time in the future when the task should be executed:
SendWelcomeEmail.enqueue(email: user.email, delay_until: Time.now + 3600) # execute in 1 hour
Defined Under Namespace
Modules: Backends, Task Classes: Metadata, Proxy, PushTimeout, Queue
Class Method Summary collapse
-
.wrap(instance, delay: nil, delay_until: nil) ⇒ Object
Push an instance to the deferred queue without including the
Rage::Deferred::Task
module.
Class Method Details
.wrap(instance, delay: nil, delay_until: nil) ⇒ Object
Push an instance to the deferred queue without including the Rage::Deferred::Task
module.
50 51 52 |
# File 'lib/rage/deferred/deferred.rb', line 50 def self.wrap(instance, delay: nil, delay_until: nil) Rage::Deferred::Proxy.new(instance, delay:, delay_until:) end |