Class: BackgroundQueue::Worker::Environment
- Inherits:
-
Object
- Object
- BackgroundQueue::Worker::Environment
- Defined in:
- lib/background_queue/worker/environment.rb
Overview
holds the params, controller and response
Defined Under Namespace
Classes: Server
Instance Attribute Summary collapse
-
#job_id ⇒ Object
readonly
Returns the value of attribute job_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#owner_id ⇒ Object
readonly
Returns the value of attribute owner_id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#server_address ⇒ Object
readonly
Returns the value of attribute server_address.
-
#task_id ⇒ Object
readonly
Returns the value of attribute task_id.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #init_from_controller(controller) ⇒ Object
- #init_params(controller_params) ⇒ Object
- #init_server_address(controller) ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #send_data(data) ⇒ Object
- #set_output(out) ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
17 18 19 |
# File 'lib/background_queue/worker/environment.rb', line 17 def initialize @params = {} end |
Instance Attribute Details
#job_id ⇒ Object (readonly)
Returns the value of attribute job_id.
6 7 8 |
# File 'lib/background_queue/worker/environment.rb', line 6 def job_id @job_id end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
11 12 13 |
# File 'lib/background_queue/worker/environment.rb', line 11 def logger @logger end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
15 16 17 |
# File 'lib/background_queue/worker/environment.rb', line 15 def output @output end |
#owner_id ⇒ Object (readonly)
Returns the value of attribute owner_id.
5 6 7 |
# File 'lib/background_queue/worker/environment.rb', line 5 def owner_id @owner_id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/background_queue/worker/environment.rb', line 4 def params @params end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
8 9 10 |
# File 'lib/background_queue/worker/environment.rb', line 8 def priority @priority end |
#server_address ⇒ Object (readonly)
Returns the value of attribute server_address.
13 14 15 |
# File 'lib/background_queue/worker/environment.rb', line 13 def server_address @server_address end |
#task_id ⇒ Object (readonly)
Returns the value of attribute task_id.
7 8 9 |
# File 'lib/background_queue/worker/environment.rb', line 7 def task_id @task_id end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
10 11 12 |
# File 'lib/background_queue/worker/environment.rb', line 10 def worker @worker end |
Instance Method Details
#init_from_controller(controller) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/background_queue/worker/environment.rb', line 21 def init_from_controller(controller) @controller = controller @logger = controller.logger init_params(controller.params) init_server_address(controller) end |
#init_params(controller_params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/background_queue/worker/environment.rb', line 28 def init_params(controller_params) hash_data = nil begin hash_data = JSON.load(controller_params[:task]) rescue Exception=>e raise "Invalid data format (should be json) when loading task from buffer: #{e.}" end raise 'Invalid json root object (should be hash)' unless hash_data.kind_of?(Hash) @params = BackgroundQueue::Utils::AnyKeyHash.new(hash_data['params']) @owner_id = hash_data['owner_id'] @job_id = hash_data['job_id'] @task_id = hash_data['id'] @priority = hash_data['priority'] @worker = hash_data['worker'] end |
#init_server_address(controller) ⇒ Object
54 55 56 |
# File 'lib/background_queue/worker/environment.rb', line 54 def init_server_address(controller) @server_address = BackgroundQueue::Worker::Environment::Server.new(controller.request.remote_ip, controller.params[:server_port]) end |
#send_data(data) ⇒ Object
49 50 51 52 |
# File 'lib/background_queue/worker/environment.rb', line 49 def send_data(data) @output.write("#{data}\n") @output.flush end |
#set_output(out) ⇒ Object
45 46 47 |
# File 'lib/background_queue/worker/environment.rb', line 45 def set_output(out) @output = out end |