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.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#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.
- #revert_environment ⇒ Object
- #send_data(data) ⇒ Object
- #set_output(out) ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
19 20 21 |
# File 'lib/background_queue/worker/environment.rb', line 19 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.
17 18 19 |
# File 'lib/background_queue/worker/environment.rb', line 17 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.
15 16 17 |
# File 'lib/background_queue/worker/environment.rb', line 15 def server_address @server_address end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
13 14 15 |
# File 'lib/background_queue/worker/environment.rb', line 13 def step @step end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
12 13 14 |
# File 'lib/background_queue/worker/environment.rb', line 12 def summary @summary 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
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/background_queue/worker/environment.rb', line 23 def init_from_controller(controller) @controller = controller init_params(controller.params) if BackgroundQueue::Worker::Config.separate_logs? @logger = BackgroundQueue::Worker::Logger.init_logger(@worker, @owner_id, @job_id , @task_id, controller.logger.level) else @logger = controller.logger end init_server_address(controller) end |
#init_params(controller_params) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/background_queue/worker/environment.rb', line 34 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'] summary_data = nil begin summary_data = JSON.load(controller_params[:summary]) unless controller_params[:summary].nil? rescue Exception=>e raise "Invalid data format (should be json) when loading summary from buffer: #{e.}" end if summary_data.nil? @summary = {} else @summary = BackgroundQueue::Utils::AnyKeyHash.new(summary_data) end @step = controller_params[:step] end |
#init_server_address(controller) ⇒ Object
74 75 76 |
# File 'lib/background_queue/worker/environment.rb', line 74 def init_server_address(controller) @server_address = BackgroundQueue::Worker::Environment::Server.new(controller.request.remote_ip, controller.params[:server_port]) end |
#revert_environment ⇒ Object
78 79 80 |
# File 'lib/background_queue/worker/environment.rb', line 78 def revert_environment end |
#send_data(data) ⇒ Object
69 70 71 72 |
# File 'lib/background_queue/worker/environment.rb', line 69 def send_data(data) @output.write("#{data}\n") @output.flush end |
#set_output(out) ⇒ Object
65 66 67 |
# File 'lib/background_queue/worker/environment.rb', line 65 def set_output(out) @output = out end |