Class: GoodData::LCM2::PurgeClients

Inherits:
BaseAction show all
Defined in:
lib/gooddata/lcm/actions/purge_clients.rb

Constant Summary collapse

DESCRIPTION =
'Purge LCM Clients'
PARAMS =
define_params(self) do
  description 'Client projects'
  param :client_projects, instance_of(Type::GdSmartHashType), required: false
end
RESULT_HEADER =
[
  :client_id,
  :project,
  :status
]

Constants inherited from BaseAction

BaseAction::FAILED_CLIENTS, BaseAction::FAILED_PROJECTS, BaseAction::FAILED_SEGMENTS, BaseAction::SYNC_FAILED_LIST

Constants included from Dsl::Dsl

Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES

Class Method Summary collapse

Methods inherited from BaseAction

add_failed_client, add_failed_project, add_failed_segment, add_new_clients_to_project_client_mapping, check_params, collect_synced_status, continue_on_error, print_result, process_failed_project, process_failed_projects, sync_failed_client, sync_failed_project, sync_failed_segment, without_check

Methods included from Dsl::Dsl

#define_params, #define_type, #process

Class Method Details

.call(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gooddata/lcm/actions/purge_clients.rb', line 26

def call(params)
  client_projects = params.client_projects

  results = client_projects.pmap do |_, info|
    client = info[:segment_client]
    project = info[:project]

    res = {
      client_id: client.client_id,
      project: project && project.pid
    }

    if project.nil? || project.deleted?
      client.delete
      res[:status] = 'purged'
    else
      res[:status] = 'ok - not purged'
    end

    res
  end

  results.pselect { |res| res[:status] == 'purged' }.pmap { |res| res[:client_id] }.each { |id| client_projects.delete(id) }

  {
    results: results,
    params: {
      client_projects: client_projects
    }
  }
end