Class: Async
- Inherits:
-
Object
- Object
- Async
- Defined in:
- lib/async.rb,
lib/async/qu.rb,
lib/async/locked.rb,
lib/async/resque.rb,
lib/async/sidekiq.rb,
lib/async/version.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ErrorReporting, Job, Lock, Locked, MethodCatcher, Notifications, QuBackend, ResqueBackend, SidekiqBackend
Constant Summary collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.backend ⇒ Object
Returns the value of attribute backend.
-
.lock_time ⇒ Object
Returns the value of attribute lock_time.
-
.redis ⇒ Object
Returns the value of attribute redis.
Class Method Summary collapse
- .ensure_backend! ⇒ Object
- .run(&block) ⇒ Object
- .run_later(job_class, receiver, method_name, *args) ⇒ Object
- .run_now(receiver, method_name, args) ⇒ Object
Class Attribute Details
.backend ⇒ Object
Returns the value of attribute backend.
3 4 5 |
# File 'lib/async.rb', line 3 def backend @backend end |
.lock_time ⇒ Object
Returns the value of attribute lock_time.
3 4 5 |
# File 'lib/async/locked.rb', line 3 def lock_time @lock_time end |
.redis ⇒ Object
Returns the value of attribute redis.
3 4 5 |
# File 'lib/async/locked.rb', line 3 def redis @redis end |
Class Method Details
.ensure_backend! ⇒ Object
14 15 16 17 18 |
# File 'lib/async.rb', line 14 def self.ensure_backend! unless Async.backend raise "Please configure the background processing system of choice by setting: Async.backend=" end end |
.run(&block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/async.rb', line 20 def self.run(&block) ensure_backend! receiver = block.binding.eval("self") mc = MethodCatcher.new mc.instance_eval(&block) run_later self.to_s, receiver, mc._method_name, *mc._args end |
.run_later(job_class, receiver, method_name, *args) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/async.rb', line 28 def self.run_later(job_class, receiver, method_name, *args) if receiver.is_a?(Class) receiver_class, receiver_id = receiver.to_s, nil else receiver_class, receiver_id = receiver.class.to_s, receiver.id end Async.backend.enqueue Async.backend.job_class, job_class, receiver_class, receiver_id, method_name, Job.transform_args(args) end |
.run_now(receiver, method_name, args) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/async.rb', line 37 def self.run_now(receiver, method_name, args) Notifications.notify_job("run", receiver, method_name, args) receiver.send(method_name, *args) ensure Notifications.notify_job("finish", receiver, method_name, args) end |