158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/gooddata/lcm/actions/update_metric_formats.rb', line 158
def call(params)
data = load_metric_data(params)
result = []
return result if data.nil?
metric_group = get_clients_metrics(data)
return result if metric_group.empty?
GoodData.logger.debug("Clients have metrics which will be modified: #{metric_group.keys}")
updated_clients = params.synchronize.map { |segment| segment.to.map { |client| client[:client_id] } }.flatten.uniq
GoodData.logger.debug("Updating clients: #{updated_clients}")
data_product = params.data_product
data_product_clients = data_product.clients
number_client_ok = 0
number_client_error = 0
collect_synced_status = collect_synced_status(params)
metric_group.each do |client_id, formats|
next if !updated_clients.include?(client_id) || (collect_synced_status && sync_failed_client(client_id, params))
client = data_product_clients.find { |c| c.id == client_id }
begin
GoodData.logger.info("Start updating metric format for client: '#{client_id}'")
metrics = client.project.metrics.to_a
formats.each do |tag, format|
next if tag.blank? || format.blank?
metrics_to_be_updated = metrics.select { |metric| metric.tags.include?(tag) }
metrics_to_be_updated.each do |metric|
metric.format = format
metric.save
end
end
number_client_ok += 1
GoodData.logger.info("Finished updating metric format for client: '#{client_id}'")
rescue StandardError => e
number_client_error += 1
GoodData.logger.warn("Failed to update metric format for client: '#{client_id}'. Error: #{e.message} - #{e}")
end
end
[{ :action => 'Update metric format', :ok_clients => number_client_ok, :error_clients => number_client_error }]
end
|