Module: Redis::Promise::Resque::ClassMethods
- Defined in:
- lib/redis/promise/resque.rb
Overview
@requires_ancestor: Kernel
Instance Method Summary collapse
-
#enqueue(*args) ⇒ Object
: (*top) -> Promise.
-
#expire ⇒ Object
The amount of time after which the resolved/rejected value will get deleted from redis.
-
#perform(promise_key, *args) ⇒ Object
: (String, *untyped) -> void.
-
#promise_redis ⇒ Object
Returns a custom redis connection that will be used in promises and resolvers.
-
#run(&block) ⇒ Object
Defines the body of the job.
Instance Method Details
#enqueue(*args) ⇒ Object
: (*top) -> Promise
33 34 35 36 37 38 |
# File 'lib/redis/promise/resque.rb', line 33 def enqueue(*args) promise = Promise.new(promise_redis) T.unsafe(::Resque).enqueue(self, promise.key, *args) # rubocop:disable Sorbet/ForbidTUnsafe promise end |
#expire ⇒ Object
The amount of time after which the resolved/rejected value will get deleted from redis.
By default ‘nil` which means it will never be deleted.
: -> Integer?
30 |
# File 'lib/redis/promise/resque.rb', line 30 def expire = nil |
#perform(promise_key, *args) ⇒ Object
: (String, *untyped) -> void
41 |
# File 'lib/redis/promise/resque.rb', line 41 def perform(promise_key, *args); end |
#promise_redis ⇒ Object
Returns a custom redis connection that will be used in promises and resolvers.
By default it uses ‘Resque.redis`
: -> Redis
22 |
# File 'lib/redis/promise/resque.rb', line 22 def promise_redis = ::Resque.redis |
#run(&block) ⇒ Object
Defines the body of the job.
Returned value will be used to resolve the promise. Any thrown errors are caught and used to reject the promise.
: { (untyped) -> void } -> void
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/redis/promise/resque.rb', line 49 def run(&block) define_singleton_method :perform do |promise_key, *args| promise = Promise::Resolver.new(promise_redis, key: promise_key) begin result = block.call(*args) promise.resolve(result) rescue StandardError => e promise.reject("[#{e.class}]: #{e.}") end end end |