Class: Actions::Insights::EmailPoller

Inherits:
Base
  • Object
show all
Includes:
RedhatAccess::Telemetry::LookUps
Defined in:
app/lib/actions/insights/email_poller.rb

Defined Under Namespace

Classes: RunOnceCoordinatorLock

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RedhatAccess::Telemetry::LookUps

#can_mask_rules, #can_unregister_system, #current_organization, #disconnected_org?, #get_basic_auth_options, #get_branch_id_for_org, #get_branch_id_for_uuid, #get_content_host, #get_content_hosts, #get_default_ssl_ca_file, #get_http_options, #get_http_user_agent, #get_leaf_id, #get_mutual_tls_auth_options, #get_organization, #get_plugin_parent_name, #get_plugin_parent_version, #get_portal_http_proxy, #get_rha_plugin_name, #get_rha_plugin_rpm_name, #get_rha_plugin_version, #get_ssl_options_for_org, #get_ssl_options_for_uuid, #get_telemetry_config, #is_org_selected?, #is_susbcribed_to_redhat?, #telemetry_enabled?, #telemetry_enabled_for_uuid?, #use_basic_auth?, #user_login_to_hash

Class Attribute Details

.triggered_actionObject (readonly)

Returns the value of attribute triggered_action.



14
15
16
# File 'app/lib/actions/insights/email_poller.rb', line 14

def triggered_action
  @triggered_action
end

Class Method Details

.ensure_running(world = ForemanTasks.dynflow.world) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/lib/actions/insights/email_poller.rb', line 15

def ensure_running(world = ForemanTasks.dynflow.world)
  world.coordinator.acquire(RunOnceCoordinatorLock.new(world)) do
    unless ForemanTasks::Task::DynflowTask.for_action(self).any?
      params = {:mode => :recurring,
                :input_type => :cronline,
                :cronline => "0 0 * * 6"}
      @triggered_action = ForemanTasks::Triggering.new_from_params(params).trigger(self)
    end
  end
rescue Dynflow::Coordinator::LockError
  return false
end

Instance Method Details

#humanized_nameObject



29
30
31
# File 'app/lib/actions/insights/email_poller.rb', line 29

def humanized_name
  N_('Insights Email Notifications')
end

#planObject



33
34
35
36
37
# File 'app/lib/actions/insights/email_poller.rb', line 33

def plan
  # Make sure we only have one instance
  Rails.logger.debug("Planning Task ")
  plan_self
end

#rescue_strategy_for_selfObject



57
58
59
# File 'app/lib/actions/insights/email_poller.rb', line 57

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#runObject



39
40
41
42
43
44
45
46
# File 'app/lib/actions/insights/email_poller.rb', line 39

def run
  Rails.logger.debug("Running Task")
  Organization.all.each do |org|
     if telemetry_enabled?(org) && is_susbcribed_to_redhat?(org)
       weekly_summary(org)
     end
  end
end

#weekly_summary(org) ⇒ Object



48
49
50
51
52
53
54
# File 'app/lib/actions/insights/email_poller.rb', line 48

def weekly_summary(org)
  message_svc = RedhatAccess::Telemetry::MessagingService.new(org)
  weekly_data_list = message_svc.all_weekly_mail_data
  weekly_data_list.each do |info|
    RedhatAccess::InsightsMailer.weekly_email(info[:user], info[:data], "Insights Weekly Summary",org).deliver_now
  end
end