Sha256: 21f8fcb6c4248f3a62c05af09e82d68edb2c114f2c840cbace518b8a3695a835

Contents?: true

Size: 1.47 KB

Versions: 19

Compression:

Stored size: 1.47 KB

Contents

module Actions
  class CheckLongRunningTasks < ::Actions::EntryAction
    include Actions::RecurringAction

    INTERVAL = 2.days
    STATES = ['running', 'paused'].freeze

    def plan
      time = Time.now.utc
      cutoff = time - INTERVAL
      users = User.joins(:mail_notifications)
                  .where(mail_enabled: true, mail_notifications: { name: 'long_running_tasks' })
                  .where.not(mail: [nil, ''])
                  .where(disabled: [nil, false])

      query = "state ^ (#{STATES.join(', ')}) AND state_updated_at <= \"#{cutoff}\""
      users.each do |user|
        User.as(user) do
          tasks = ForemanTasks::Task.authorized
                                    .search_for(query)
                                    .select(:id)
                                    .pluck(:id)
          plan_action(DeliverLongRunningTasksNotification,
                      OpenStruct.new(
                        user_id: User.current.id,
                        time: time,
                        interval: INTERVAL,
                        states: STATES,
                        task_uuids: tasks,
                        query: query,
                        # Non serializable fields
                        user: nil,
                        tasks: nil
                      ))
        end
      end
    end

    def humanized_name
      _('Check for long running tasks')
    end

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-10.0.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-10.0.0 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.2.3 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.2.2 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.2.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.2.0 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.1.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.0.4 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.1.0 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.0.2 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.0.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.3.3 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-9.0.0 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.2.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.1.4 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.3.2 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.3.1 app/lib/actions/check_long_running_tasks.rb
foreman-tasks-8.1.3 app/lib/actions/check_long_running_tasks.rb