Class: Thor::Job
- Inherits:
-
Application
- Object
- Bsl::Application
- Application
- Thor::Job
- Defined in:
- lib/ThorJob.rb
Direct Known Subclasses
Thor::Jobs::Client, Thor::Jobs::Master, Thor::Jobs::MonitorClient, Thor::Jobs::MonitorMaster, Thor::Jobs::Node
Constant Summary collapse
- @@AUTHOR =
"<no author>"
- @@DESCRIPTION =
"<no description>"
- @@LICENSE =
"<no license>"
- @@VERSION =
"<no version>"
- @@SUPPORTED_MSGS =
[]
Instance Attribute Summary collapse
-
#amqp_conn ⇒ Object
Returns the value of attribute amqp_conn.
-
#em_conn ⇒ Object
Returns the value of attribute em_conn.
-
#sql_conn ⇒ Object
Returns the value of attribute sql_conn.
-
#thread ⇒ Object
Returns the value of attribute thread.
Attributes inherited from Application
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Job
constructor
C-tor.
-
#is_running? ⇒ Boolean
Checks if is thread running.
-
#main ⇒ Object
Called when running as app.
-
#process_msg(channel, exchange, msg) ⇒ Object
Process Message.
-
#run(opts = {}) ⇒ Object
Start - Called when included in library.
-
#start(opts = {}, wait = false) ⇒ Object
Start - Called when included in library.
-
#stop(opts = {}) ⇒ Object
Stop - Called when included in library.
Methods inherited from Application
#amqp_handle_failure, #amqp_loop, #amqp_start, #amqp_stop
Constructor Details
#initialize(opts = {}) ⇒ Job
C-tor
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ThorJob.rb', line 54 def initialize(opts = {}) super(opts) @thread = nil @amqp_conn = nil @em_conn = nil @sql_conn = nil klass_name = self.class.name name_exchange_direct_global = "#{klass_name}.direct" name_exchange_direct_local= "#{klass_name}.direct.#{Thor::generate_guid}" name_exchange_fanout = "#{klass_name}.fanout" name_exchange_topic = "#{klass_name}.topic" if(false && [:verbose]) Bsl::Logger::Log "#{klass_name} exchange direct (global) name: #{name_exchange_direct_global}" Bsl::Logger::Log "#{klass_name} exchange direct (local) name: #{name_exchange_direct_local}" Bsl::Logger::Log "#{klass_name} exchange fanout name: #{name_exchange_fanout}" Bsl::Logger::Log "#{klass_name} exchange topic name: #{name_exchange_topic}" end end |
Instance Attribute Details
#amqp_conn ⇒ Object
Returns the value of attribute amqp_conn.
25 26 27 |
# File 'lib/ThorJob.rb', line 25 def amqp_conn @amqp_conn end |
#em_conn ⇒ Object
Returns the value of attribute em_conn.
25 26 27 |
# File 'lib/ThorJob.rb', line 25 def em_conn @em_conn end |
#sql_conn ⇒ Object
Returns the value of attribute sql_conn.
25 26 27 |
# File 'lib/ThorJob.rb', line 25 def sql_conn @sql_conn end |
#thread ⇒ Object
Returns the value of attribute thread.
25 26 27 |
# File 'lib/ThorJob.rb', line 25 def thread @thread end |
Class Method Details
.author ⇒ Object
33 34 35 |
# File 'lib/ThorJob.rb', line 33 def self. return @@AUTHOR end |
.description ⇒ Object
37 38 39 |
# File 'lib/ThorJob.rb', line 37 def self.description return @@DESCRIPTION end |
.license ⇒ Object
41 42 43 |
# File 'lib/ThorJob.rb', line 41 def self.license return @@LICENSE end |
.supported_msgs ⇒ Object
49 50 51 |
# File 'lib/ThorJob.rb', line 49 def self.supported_msgs return @@SUPPORTED_MSGS end |
.version ⇒ Object
45 46 47 |
# File 'lib/ThorJob.rb', line 45 def self.version return @@VERSION end |
Instance Method Details
#is_running? ⇒ Boolean
Checks if is thread running
138 139 140 |
# File 'lib/ThorJob.rb', line 138 def is_running? return (@thread != nil) end |
#main ⇒ Object
Called when running as app
78 79 80 81 82 83 |
# File 'lib/ThorJob.rb', line 78 def main() @thread = Thread.new do run() end @thread.join! end |
#process_msg(channel, exchange, msg) ⇒ Object
Process Message
86 87 88 89 90 |
# File 'lib/ThorJob.rb', line 86 def process_msg(channel, exchange, msg) if([:verbose]) Bsl::Logger::Log "Thor::Job::process_msg()" end end |
#run(opts = {}) ⇒ Object
Start - Called when included in library
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ThorJob.rb', line 93 def run(opts = {}) super(opts) if([:verbose]) Bsl::Logger::Log "Thor::Job::run()" end # Extract raw AMQP connection tmp = [:amqp] amqp_conn = tmp[:conn] if tmp # Extract raw Event Machine connection tmp = [:em] em_conn = tmp[:conn] if tmp # Extract raw SQL connection tmp = [:sql] sql_conn = tmp[:conn] if tmp #sleep 10 end |
#start(opts = {}, wait = false) ⇒ Object
Start - Called when included in library
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ThorJob.rb', line 116 def start(opts = {}, wait = false) #puts "#{options[:amqp].inspect}" @thread = Thread.new do #puts opts.inspect self.run(opts) end if wait @thread.join! return true end return true end |
#stop(opts = {}) ⇒ Object
Stop - Called when included in library
131 132 133 134 135 |
# File 'lib/ThorJob.rb', line 131 def stop(opts = {}) return false if @thread == nil @thread.kill! @thread = nil end |