Sha256: 3a8063e1865a9e5c1ee99d8dc22972beb77d0d0ed1d612cd3de0787dc07249b1

Contents?: true

Size: 1.95 KB

Versions: 29

Compression:

Stored size: 1.95 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"}
              triggering = ForemanTasks::Triggering.new_from_params(params)
              triggering.save!
              triggering.reload
              @triggered_action = triggering.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

29 entries across 29 versions & 1 rubygems

Version Path
redhat_access-2.9.1 app/lib/actions/insights/email_poller.rb
redhat_access-2.8.1 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.20 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.19 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.18 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.17 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.16 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.15 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.14 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.13 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.12 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.11 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.10 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.9 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.8 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.7 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.10 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.9 app/lib/actions/insights/email_poller.rb
redhat_access-2.2.6 app/lib/actions/insights/email_poller.rb
redhat_access-2.1.8 app/lib/actions/insights/email_poller.rb