Class: ForemanRhCloud::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/foreman_rh_cloud/engine.rb

Class Method Summary collapse

Class Method Details

.register_scheduled_task(task_class, cronline) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/foreman_rh_cloud/engine.rb', line 8

def self.register_scheduled_task(task_class, cronline)
  ForemanTasks::RecurringLogic.transaction(isolation: :serializable) do
    return if ForemanTasks::RecurringLogic.joins(:tasks)
              .merge(ForemanTasks::Task.where(label: task_class.name))
              .exists?

    User.as_anonymous_admin do
      recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
      recurring_logic.save!
      recurring_logic.start(task_class)
    end
  end
rescue ActiveRecord::TransactionIsolationError
end