Module: WarpCore
- Defined in:
- lib/warpcore/cache.rb,
lib/warpcore/sidekiq.rb,
lib/warpcore/version.rb,
lib/warpcore/dispatch.rb
Defined Under Namespace
Classes: Cache, ParallelDispatchQueue, RedisPoolInstance, SerialDispatchQueue
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Class Method Details
.async(type = :serial) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/warpcore/dispatch.rb', line 24
def self.async(type = :serial)
raise "You need to pass a block to async." unless block_given?
if type == :parallel
WarpCore::ParallelDispatchQueue.perform_async Proc.new
else
WarpCore::SerialDispatchQueue.perform_async Proc.new
end
end
|
.cache(key, opts = {}) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/warpcore/cache.rb', line 7
def self.cache(key,opts = {})
if block_given?
WarpCore::Cache.get( key, opts, Proc.new )
else
WarpCore::Cache.get( key, opts )
end
end
|
.delay_by(seconds, type = :serial) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/warpcore/dispatch.rb', line 33
def self.delay_by(seconds, type = :serial)
raise "You need to pass a block to delay_by." unless block_given?
if type == :parallel
WarpCore::ParallelDispatchQueue.perform_in seconds.to_i, Proc.new
else
WarpCore::SerialDispatchQueue.perform_in seconds.to_i, Proc.new
end
end
|
.dispatch(worker_name, *args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/warpcore/sidekiq.rb', line 12
def self.dispatch(worker_name, *args)
klass = worker_name.constantize
if klass.respond_to?(:perform_async)
puts "=> [Dispatch:Async] #{worker_name}"
return klass.perform_async(*args)
else
warn "Dispatched #{worker_name} not a valid Sidekiq worker."
nil
end
rescue NameError => e
puts "Worker [#{worker_name}] not defined."
nil
end
|
.dispatch_in(worker_name, *args) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/warpcore/sidekiq.rb', line 26
def self.dispatch_in(worker_name, *args)
klass = worker_name.constantize
if klass.respond_to?(:perform_async)
puts "=> [Dispatch:Delay] #{worker_name}"
return klass.perform_in(*args)
else
warn "Dispatched #{worker_name} not a valid Sidekiq worker."
nil
end
rescue NameError => e
puts "Worker [#{worker_name}] not defined."
nil
end
|
.dispatch_sync(worker_name, *args) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/warpcore/sidekiq.rb', line 40
def self.dispatch_sync(worker_name, *args)
klass = worker_name.constantize
object = klass.new
if object.respond_to?(:perform)
puts "=> [Dispatch:Sync] #{worker_name}"
return object.perform(*args)
else
warn "Perform #{worker_name} not a valid Sidekiq worker."
nil
end
rescue NameError => e
puts "Worker [#{worker_name}] not defined."
nil
end
|