Module: Langis::Sinks
- Defined in:
- lib/langis/sinks.rb
Overview
Predefined sinks, destinations for a message pumped into the Langis Engines.
Constant Summary collapse
- DELAYED_JOB_RESULT_KEY =
The header key whose value is the DelayedJob enqueue result.
'langis.sink.delayed_job.result'
- REDIS_RESULT_KEY =
The header key whose value is the Redis rpush result.
'langis.sink.redis.result'
- RESQUE_RESULT_KEY =
The header key whose value is the Resque enqueue result.
'langis.sink.resque.result'
Class Method Summary collapse
-
.delayed_job(job_class, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will enqueue a new instance of a DelayedJob job class with instantiation parameters extracted from the Rackish input environment.
-
.redis(connection, key, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will rpush an input environment’s value into a list stored in a Redis database.
-
.resque(job_class, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will rpush an input environment’s value into a list stored in a Redis database.
Class Method Details
.delayed_job(job_class, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will enqueue a new instance of a DelayedJob job class with instantiation parameters extracted from the Rackish input environment.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/langis/sinks.rb', line 35 def delayed_job(job_class, ={}) priority = [:priority] || 0 run_at = [:run_at] env_key = [:env_key] || MESSAGE_KEY xform = [:transform] xform_args = [:transform_args] || [] xform_args = [xform_args] unless xform_args.is_a? Array lambda { |env| = env[env_key] if xform.is_a? Symbol and .respond_to? xform args = .send(xform, *xform_args) else args = end args = [args] unless args.is_a? Array result = Delayed::Job.enqueue job_class.new(*args), priority, run_at return [OK, { DELAYED_JOB_RESULT_KEY => result }, ['']] } end |
.redis(connection, key, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will rpush an input environment’s value into a list stored in a Redis database.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/langis/sinks.rb', line 77 def redis(connection, key, ={}) env_key = [:env_key] || MESSAGE_KEY xform = [:transform] xform_args = [:transform_args] || [] xform_args = [xform_args] unless xform_args.is_a? Array lambda { |env| = env[env_key] if xform.is_a? Symbol and .respond_to? xform = .send(xform, *xform_args) end result = connection.rpush key, return [OK, { REDIS_RESULT_KEY => result }, ['']] } end |
.resque(job_class, options = {}) ⇒ Array<Integer,Hash,#each>
Module function that creates the endpoint Rackish app that will rpush an input environment’s value into a list stored in a Redis database.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/langis/sinks.rb', line 119 def resque(job_class, ={}) env_key = [:env_key] || MESSAGE_KEY xform = [:transform] xform_args = [:transform_args] || [] xform_args = [xform_args] unless xform_args.is_a? Array lambda { |env| = env[env_key] if xform.is_a? Symbol and .respond_to? xform args = .send(xform, *xform_args) else args = end args = [args] unless args.is_a? Array result = Resque.enqueue job_class, *args return [OK, { RESQUE_RESULT_KEY => result }, ['']] } end |