Class: Thor::Job

Inherits:
Application show all
Defined in:
lib/ThorJob.rb

Constant Summary collapse

@@AUTHOR =
"<no author>"
@@DESCRIPTION =
"<no description>"
@@LICENSE =
"<no license>"
@@VERSION =
"<no version>"
@@SUPPORTED_MSGS =
[]

Instance Attribute Summary collapse

Attributes inherited from Application

#request_exit

Class Method Summary collapse

Instance Method Summary collapse

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 && options[: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_connObject

Returns the value of attribute amqp_conn.



25
26
27
# File 'lib/ThorJob.rb', line 25

def amqp_conn
  @amqp_conn
end

#em_connObject

Returns the value of attribute em_conn.



25
26
27
# File 'lib/ThorJob.rb', line 25

def em_conn
  @em_conn
end

#sql_connObject

Returns the value of attribute sql_conn.



25
26
27
# File 'lib/ThorJob.rb', line 25

def sql_conn
  @sql_conn
end

#threadObject

Returns the value of attribute thread.



25
26
27
# File 'lib/ThorJob.rb', line 25

def thread
  @thread
end

Class Method Details

.authorObject



33
34
35
# File 'lib/ThorJob.rb', line 33

def self.author
  return @@AUTHOR
end

.descriptionObject



37
38
39
# File 'lib/ThorJob.rb', line 37

def self.description
  return @@DESCRIPTION
end

.licenseObject



41
42
43
# File 'lib/ThorJob.rb', line 41

def self.license
  return @@LICENSE
end

.supported_msgsObject



49
50
51
# File 'lib/ThorJob.rb', line 49

def self.supported_msgs
  return @@SUPPORTED_MSGS
end

.versionObject



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

#mainObject

Called when running as app



78
79
80
81
82
83
# File 'lib/ThorJob.rb', line 78

def main()
  @thread = Thread.new do
    run(options)
  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(options[: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(options[:verbose])
    Bsl::Logger::Log "Thor::Job::run()"
  end

  # Extract raw AMQP connection
  tmp = options[:amqp]
  amqp_conn = tmp[:conn] if tmp

  # Extract raw Event Machine connection
  tmp = options[:em]
  em_conn = tmp[:conn] if tmp

  # Extract raw SQL connection
  tmp = options[: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