Project

General

Profile

« Previous | Next » 

Revision e5b4634f

Added by Adam Ruzicka almost 6 years ago

  • Fixes #23611 - Provide helper method to run "service" active jobs

The root cause was we were triggering the active jobs too early,
sometimes even before the db was migrated. This led to all sorts of
errors. The provided helper method does not trigger the jobs when in
any rake or in test environment. This helper should be reused in
Katello as well.

View differences:

config/initializers/rss_notifications.rb
# First, we check if there's a job already enqueued for RSS notifications
::Foreman::Application.dynflow.config.on_init do |world|
pending_jobs = world.persistence.find_execution_plans(filters: { :state => 'scheduled' })
scheduled_job = pending_jobs.select do |job|
delayed_plan = world.persistence.load_delayed_plan job.id
next unless delayed_plan.present?
delayed_plan.to_hash[:serialized_args].first.try(:[], 'job_class') == 'CreateRssNotifications'
end
# Only create notifications if there isn't a scheduled job
CreateRssNotifications.perform_later if !Rails.env.test? && scheduled_job.blank?
CreateRssNotifications.spawn_if_missing(world)
end

Also available in: Unified diff