module WarpCore
This module provides a set of classes and components to build large scale, scalable and easier to maintain ruby-based applications with Parse.
Constants
- VERSION
Version number
Public Class Methods
Helper method to run a block on a background thread. @param type [Symbol] the queue to use when dispatching the block.
* :serial - use the {SerialDispatchQueue} * :parallel - use the {ParallelDispatchQueue}
# File lib/warpcore/dispatch.rb, line 29 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
# 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
Helper method to run a block on a background thread. @param type (see WarpCore.async
)
* :serial - use the {SerialDispatchQueue} * :parallel - use the {ParallelDispatchQueue}
# File lib/warpcore/dispatch.rb, line 42 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
Asynchronously dispatch a Sidekiq worker with the provided arguments. This is equivalent to calling the worker directly with `perform_async`. @example
WarpCore.dispatch 'Workers::MyWorker', argument1, argument2.....
@param worker_name [String] the full class path of the worker (ex. `Workers::MyWorker`) @param args [Array] the arguments to pass to the worker.
# File lib/warpcore/sidekiq.rb, line 19 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
Asynchronously dispatch a Sidekiq worker at a later time with the provided arguments. This is equivalent to calling the worker directly with `perform_in`. @example
WarpCore.dispatch_in 'Workers::MyWorker', 10.seconds, argument1, argument2.....
@param worker_name (see WarpCore.dispatch
) @param args [Array] the arguments to pass to the worker. The first argument
should be the amount of time to wait before dispatching the worker.
# File lib/warpcore/sidekiq.rb, line 40 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
Synchronously dispatch a Sidekiq worker with the provided arguments. This is equivalent to instantiating the worker instance directly and calling `perform` on it. @example
WarpCore.dispatch_sync 'Workers::MyWorker', argument1, argument2.....
@param worker_name (see WarpCore.dispatch
) @param args [Array] the arguments to pass to the worker.
# File lib/warpcore/sidekiq.rb, line 61 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
@return [RedisPoolInstance] a usable redis instance shared by Sidekiq.
# File lib/warpcore/sidekiq.rb, line 9 def self.redis WarpCore::RedisPoolInstance.new end