Class: VWO::Services::BatchEventsDispatcher

Inherits:
Object
  • Object
show all
Includes:
Enums, Utils::Utility
Defined in:
lib/vwo/services/batch_events_dispatcher.rb

Constant Summary

Constants included from CONSTANTS

CONSTANTS::API_VERSION, CONSTANTS::DEFAULT_EVENTS_PER_REQUEST, CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL, CONSTANTS::GOAL_TYPES, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_EVENTS_PER_REQUEST, CONSTANTS::MAX_RANGE, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::MIN_EVENTS_PER_REQUEST, CONSTANTS::MIN_REQUEST_TIME_INTERVAL, CONSTANTS::PLATFORM, CONSTANTS::RUBY_VARIABLE_TYPES, CONSTANTS::SDK_NAME, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE, CONSTANTS::VWO_DELIMITER

Instance Method Summary collapse

Methods included from Utils::Utility

#convert_to_symbol_hash, #get_url, #get_variation_identifiers, #prepare_push_response, #remove_sensitive_properties

Methods included from Utils

#valid_campaign_for_track_api?, #valid_track_api_params?

Methods included from Utils::Validations

#invalid_config_log, #valid_basic_data_type?, #valid_batch_event_settings, #valid_boolean?, #valid_config_log, #valid_goal?, #valid_hash?, #valid_number?, #valid_settings_file?, #valid_string?, #valid_value?, #validate_sdk_config?

Constructor Details

#initialize(development_mode = false) ⇒ BatchEventsDispatcher

Initialize the BatchEventDispatcher with logger and development mode



29
30
31
32
33
# File 'lib/vwo/services/batch_events_dispatcher.rb', line 29

def initialize(development_mode = false)
  @logger = VWO::Utils::Logger
  @development_mode = development_mode
  @queue = []
end

Instance Method Details

#dispatch(impression, callback, query_params) ⇒ Object

Dispatch the impression event having properties object only if dev-mode is OFF

@param :properties hash having impression properties

the request to be dispatched to the VWO server

@return



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/vwo/services/batch_events_dispatcher.rb', line 41

def dispatch(impression, callback, query_params)
  url = CONSTANTS::HTTPS_PROTOCOL + get_url(CONSTANTS::ENDPOINTS::BATCH_EVENTS)
   = query_params[:a]
  resp = VWO::Utils::Request.post(url, query_params, impression)
  case resp.code
  when '200'
    @logger.log(
      LogLevelEnum::INFO,
      'IMPRESSION_BATCH_SUCCESS',
      {
        '{file}' => FILE,
        '{endPoint}' => url,
        '{accountId}' => 
      }
    )
    message = nil
  when '413'
    @logger.log(
      LogLevelEnum::DEBUG,
      'CONFIG_BATCH_EVENT_LIMIT_EXCEEDED',
      {
        '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
        '{endPoint}' => url,
        '{eventsPerRequest}' => impression.length,
        '{accountId}' => impression[:a]
      }
    )

    @logger.log(
      LogLevelEnum::ERROR,
      'IMPRESSION_FAILED',
      {
        '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
        '{err}' => resp.message,
        '{endPoint}' => url
      }
    )
    message = resp.message
  else
    @logger.log(
      LogLevelEnum::INFO,
      'IMPRESSION_BATCH_FAILED',
      { '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER }
    )

    @logger.log(
      LogLevelEnum::ERROR,
      'IMPRESSION_FAILED',
      {
        '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
        '{err}' => resp.message,
        '{endPoint}' => url
      }
    )
    message = resp.message
  end
  callback&.call(message, impression)
  true
rescue StandardError => e
  @logger.log(
    LogLevelEnum::DEBUG,
    'IMPRESSION_BATCH_FAILED',
    { '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER }
  )

  @logger.log(
    LogLevelEnum::ERROR,
    'IMPRESSION_FAILED',
    {
      '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
      '{err}' => e.message,
      '{endPoint}' => url
    }
  )
  false
end