Module: GoodData::ContextManager
- Extended by:
- Mixin::PropertyAccessor
- Included in:
- GdLogger
- Defined in:
- lib/gooddata/bricks/middleware/context_manager.rb
Instance Method Summary collapse
-
#context(now = Time.now) ⇒ Hash
Return current brick context extended with time specific information.
-
#end_action(logger = nil) ⇒ Object
Ends currently opened lcm action.
- #initialize_context ⇒ Object
-
#start_action(next_action, logger = nil, now = Time.now) ⇒ Object
Starts lcm action.
- #time_from_action_start(now = Time.now) ⇒ Object
Methods included from Mixin::PropertyAccessor
property_accessor, property_reader, property_writer
Instance Method Details
#context(now = Time.now) ⇒ Hash
Return current brick context extended with time specific information
34 35 36 37 |
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 34 def context(now = Time.now) time_specific_context = action ? { :time => time_from_action_start(now) } : {} @context.merge(time_specific_context) end |
#end_action(logger = nil) ⇒ Object
Ends currently opened lcm action
61 62 63 64 65 66 67 |
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 61 def end_action(logger = nil) GoodData::LCM2::Helpers.fail_if_development 'No matching action to start found' unless action logger.info '' if logger self.status = :not_in_action self.action = nil end |
#initialize_context ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 18 def initialize_context @action_start = Time.now # :log_v is used to differentiate new versions of logs in splunk @context = { :api_version => GoodData.version, :log_v => 0, :component => 'lcm.ruby', :status => :not_in_action } end |
#start_action(next_action, logger = nil, now = Time.now) ⇒ Object
Starts lcm action
49 50 51 52 53 54 55 56 |
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 49 def start_action(next_action, logger = nil, now = Time.now) GoodData::LCM2::Helpers.fail_if_development 'An action is already being profiled' if action self.action = next_action @action_start = now logger.info '' if logger self.status = :action_in_progress end |
#time_from_action_start(now = Time.now) ⇒ Object
39 40 41 42 |
# File 'lib/gooddata/bricks/middleware/context_manager.rb', line 39 def time_from_action_start(now = Time.now) GoodData::LCM2::Helpers.fail_if_development 'No action is being profiled' unless action (now - @action_start) * 1000 end |