Sha256: 3a287b5c5bd6c63bb5a167e36df2170e7526faedcaa580689156c60a443d50d1

Contents?: true

Size: 1.85 KB

Versions: 21

Compression:

Stored size: 1.85 KB

Contents

module Actions
  module Insights
    class EmailPoller < Actions::Base
      include RedhatAccess::Telemetry::LookUps
      middleware.use Actions::Middleware::RecurringLogic
      class RunOnceCoordinatorLock < Dynflow::Coordinator::LockByWorld
        def initialize(world)
          super
          @data[:id] = 'insights-email-poller'
        end
      end

      class << self
        attr_reader :triggered_action
        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
      end

      def humanized_name
        N_('Insights Email Notifications')
      end

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

      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

      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


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

    end
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
redhat_access-2.0.17 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.16 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.15 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.14 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.3 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.2 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.1 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.0 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.13 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.12 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.11 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.10 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.9 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.8 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.7 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.6 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.5 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.4 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.3 app/lib/actions/insights/email_poller.rb
redhat_access-2.0.2 app/lib/actions/insights/email_poller.rb