Sha256: 6fa15b531902c552cce9e591de67c869d101f6586bc351a9d2f7f63e078376c0
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 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 notification = ::ForemanTasks::TasksMailNotification.find_by(name: "long_running_tasks") org_admin_role = Role.find_by(name: 'Organization admin') users = User.left_joins(:roles) .where(id: UserMailNotification.where(mail_notification_id: notification.id).select(:host_id)) .or(User.where(admin: true)) .or(User.where(id: UserRole.where(id: [org_admin_role.id] + org_admin_role.cloned_role_ids).select(:owner_id))) 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foreman-tasks-8.1.0 | app/lib/actions/check_long_running_tasks.rb |