Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop first_in => interval from scheduler #19385

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 27 additions & 57 deletions app/models/miq_schedule_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,51 +75,40 @@ def schedules_for_all_roles
schedule_category = :schedules_for_all_roles

# Schedule - Log current system configuration
every = worker_settings[:log_active_configuration_interval]

scheduler.schedule_every(
every,
:first_in => every,
worker_settings[:log_active_configuration_interval],
:tags => [:vmdb_appliance_log_config, schedule_category]
) { enqueue(:vmdb_appliance_log_config) }

# Schedule - Log current database statistics and bloat
every = worker_settings[:log_database_statistics_interval]
scheduler.schedule_every(
every,
:first_in => every,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't first_in => every the same as just not specifying a first_in?

I think it is... I believe we can drop first_in completely if it's the same as the interval.... less code

first_in sets first_at

first_at is used if provided, otherwise uses the interval

I'll test this but I'm pretty sure it's useless to specify first_in if it's the same as interval.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

irb(main):001:0> s = Rufus::Scheduler.new
=> #<Rufus::Scheduler:0x00007fe5778a8e50 @opts={}, @started_at=#<EtOrbi::EoTime:0x00007fe5778a8ae0 @seconds=1570814114.055407, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @paused=false, @jobs=#<Rufus::Scheduler::JobArray:0x00007fe5778a8d88 @mutex=#<Thread::Mutex:0x00007fe5778a8d60>, @array=[]>, @frequency=0.3, @mutexes={}, @work_queue=#<Thread::Queue:0x00007fe5778a8cc0>, @max_work_threads=28, @stderr=#<IO:<STDERR>>, @thread_key="rufus_scheduler_70311764903720", @scheduler_lock=#<Rufus::Scheduler::NullLock:0x00007fe5778a8ba8>, @trigger_lock=#<Rufus::Scheduler::NullLock:0x00007fe5778a8b80>, @thread=#<Thread:0x00007fe5778a8a90@/Users/joerafaniello/.gem/ruby/2.5.5/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler.rb:545 sleep>>

irb(main):002:0> job = s.schedule_every(10.minutes, :first_in => 10.minutes) { puts 'hi'}
=> #<Rufus::Scheduler::EveryJob:0x00007fe577870de8 @scheduler=#<Rufus::Scheduler:0x00007fe5778a8e50 @opts={}, @started_at=#<EtOrbi::EoTime:0x00007fe5778a8ae0 @seconds=1570814114.055407, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @paused=false, @jobs=#<Rufus::Scheduler::JobArray:0x00007fe5778a8d88 @mutex=#<Thread::Mutex:0x00007fe5778a8d60>, @array=[#<Rufus::Scheduler::EveryJob:0x00007fe577870de8 ...>]>, @frequency=0.3, @mutexes={}, @work_queue=#<Thread::Queue:0x00007fe5778a8cc0>, @max_work_threads=28, @stderr=#<IO:<STDERR>>, @thread_key="rufus_scheduler_70311764903720", @scheduler_lock=#<Rufus::Scheduler::NullLock:0x00007fe5778a8ba8>, @trigger_lock=#<Rufus::Scheduler::NullLock:0x00007fe5778a8b80>, @thread=#<Thread:0x00007fe5778a8a90@/Users/joerafaniello/.gem/ruby/2.5.5/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler.rb:545 sleep>>, @original=10 minutes, @opts={:first_in=>10 minutes}, @handler=#<Proc:0x00007fe577870f50@(irb):2>, @callable=#<Proc:0x00007fe577870f50@(irb):2>, @scheduled_at=#<EtOrbi::EoTime:0x00007fe577870d98 @seconds=1570814126.985564, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @unscheduled_at=nil, @last_time=nil, @locals={}, @local_mutex=#<Thread::Mutex:0x00007fe577870c80>, @id="every_1570814126.985564_70311764788980", @tags=[], @count=0, @last_work_time=0.0, @mean_work_time=0.0, @paused_at=nil, @times=nil, @first_at=#<EtOrbi::EoTime:0x00007fe577860b78 @seconds=1570814726.987073, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @next_time=#<EtOrbi::EoTime:0x00007fe577860b78 @seconds=1570814726.987073, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @last_at=nil, @frequency=10 minutes>

irb(main):004:0> job.next_time.to_time_s
=> "17:25:26.987072"

irb(main):006:0> job.first_at.to_time_s
=> "17:25:26.987072"
irb(main):001:0> s = Rufus::Scheduler.new
=> #<Rufus::Scheduler:0x00007ffe2e513f18 @opts={}, @started_at=#<EtOrbi::EoTime:0x00007ffe2e513900 @seconds=1570814274.907996, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @paused=false, @jobs=#<Rufus::Scheduler::JobArray:0x00007ffe2e513e50 @mutex=#<Thread::Mutex:0x00007ffe2e513e28>, @array=[]>, @frequency=0.3, @mutexes={}, @work_queue=#<Thread::Queue:0x00007ffe2e513c98>, @max_work_threads=28, @stderr=#<IO:<STDERR>>, @thread_key="rufus_scheduler_70364837748620", @scheduler_lock=#<Rufus::Scheduler::NullLock:0x00007ffe2e5139c8>, @trigger_lock=#<Rufus::Scheduler::NullLock:0x00007ffe2e513950>, @thread=#<Thread:0x00007ffe2e513860@/Users/joerafaniello/.gem/ruby/2.5.5/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler.rb:545 sleep>>
irb(main):002:0> job = s.schedule_every(10.minutes) { puts 'hi'}
=> #<Rufus::Scheduler::EveryJob:0x00007ffe2e4d0b78 @scheduler=#<Rufus::Scheduler:0x00007ffe2e513f18 @opts={}, @started_at=#<EtOrbi::EoTime:0x00007ffe2e513900 @seconds=1570814274.907996, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @paused=false, @jobs=#<Rufus::Scheduler::JobArray:0x00007ffe2e513e50 @mutex=#<Thread::Mutex:0x00007ffe2e513e28>, @array=[#<Rufus::Scheduler::EveryJob:0x00007ffe2e4d0b78 ...>]>, @frequency=0.3, @mutexes={}, @work_queue=#<Thread::Queue:0x00007ffe2e513c98>, @max_work_threads=28, @stderr=#<IO:<STDERR>>, @thread_key="rufus_scheduler_70364837748620", @scheduler_lock=#<Rufus::Scheduler::NullLock:0x00007ffe2e5139c8>, @trigger_lock=#<Rufus::Scheduler::NullLock:0x00007ffe2e513950>, @thread=#<Thread:0x00007ffe2e513860@/Users/joerafaniello/.gem/ruby/2.5.5/gems/rufus-scheduler-3.6.0/lib/rufus/scheduler.rb:545 sleep>>, @original=10 minutes, @opts={}, @handler=#<Proc:0x00007ffe2e4d0c40@(irb):2>, @callable=#<Proc:0x00007ffe2e4d0c40@(irb):2>, @scheduled_at=#<EtOrbi::EoTime:0x00007ffe2e4d0b28 @seconds=1570814298.044724, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @unscheduled_at=nil, @last_time=nil, @locals={}, @local_mutex=#<Thread::Mutex:0x00007ffe2e4d0a60>, @id="every_1570814298.044724_70364837610940", @tags=[], @count=0, @last_work_time=0.0, @mean_work_time=0.0, @paused_at=nil, @times=nil, @first_at=nil, @next_time=#<EtOrbi::EoTime:0x00007ffe2e4d0128 @seconds=1570814898.04481, @zone=#<TZInfo::DataTimezone: Etc/UTC>, @time=nil>, @last_at=nil, @frequency=10 minutes>
irb(main):003:0> job.next_time.to_time_s
=> "17:28:18.044810"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they look the same to me ^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr; remove all first_in where first_in == interval for "every" jobs

worker_settings[:log_database_statistics_interval],
:tags => [:log_all_database_statistics, schedule_category]
) { enqueue(:vmdb_database_log_all_database_statistics) }

# Schedule - Update Server Statistics
every = worker_settings[:server_stats_interval]
scheduler.schedule_every(
every,
:first_in => every,
worker_settings[:server_stats_interval],
:tags => [:status_update, schedule_category]
) { enqueue(:miq_server_status_update) }

# Schedule - Log Server and Worker Statistics
every = worker_settings[:server_log_stats_interval]
scheduler.schedule_every(
every,
:first_in => every,
worker_settings[:server_log_stats_interval],
:tags => [:log_status, schedule_category]
) { enqueue(:miq_server_worker_log_status) }

# Schedule - Periodic logging of database statistics
interval = worker_settings[:db_diagnostics_interval]
scheduler.schedule_every(
interval,
worker_settings[:db_diagnostics_interval],
:first_in => 1.minute,
:tags => [:log_statistics, schedule_category]
) { enqueue(:vmdb_database_connection_log_statistics) }

# Schedule - Periodic check for updates on appliances only
if MiqEnvironment::Command.is_appliance?
interval = worker_settings[:yum_update_check]
scheduler.schedule_every(
interval,
worker_settings[:yum_update_check],
:first_in => 1.minute,
:tags => [:server_updates, schedule_category]
) { enqueue(:miq_server_queue_update_registration_status) }
Expand All @@ -133,28 +122,25 @@ def schedules_for_scheduler_role
return unless schedule_enabled?(:scheduler)
scheduler = scheduler_for(:scheduler)
# Schedule - Check for timed out jobs
every = worker_settings[:job_timeout_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:job_timeout_interval]) do
enqueue(:job_check_jobs_for_timeout)
end

# Schedule - Check for retired items and start retirement
# TODO: remove redundant settings in follow-up pr
every = [worker_settings[:service_retired_interval], worker_settings[:vm_retired_interval], worker_settings[:orchestration_stack_retired_interval]].min
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(every) do
enqueue(:retirement_check)
end

# Schedule - Periodic validation of authentications
every = worker_settings[:authentication_check_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:authentication_check_interval]) do
# Queue authentication checks for CIs with credentials
enqueue(:host_authentication_check_schedule)
enqueue(:ems_authentication_check_schedule)
end

every = worker_settings[:drift_state_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:drift_state_purge_interval]) do
enqueue(:drift_state_purge_timer)
end

Expand All @@ -167,9 +153,8 @@ def schedules_for_scheduler_role
end

# Schedule - Check for rogue EVM snapshots
every = worker_settings[:evm_snapshot_interval]
job_not_found_delay = worker_settings[:evm_snapshot_delete_delay_for_job_not_found]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:evm_snapshot_interval]) do
enqueue([:job_check_for_evm_snapshots, job_not_found_delay])
end

Expand All @@ -192,38 +177,31 @@ def schedules_for_scheduler_role
end

# Schedule - Prune old reports Timer
every = worker_settings[:report_result_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:report_result_purge_interval]) do
enqueue(:miq_report_result_purge_timer)
end

every = worker_settings[:container_entities_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:container_entities_purge_interval]) do
enqueue(:archived_entities_purge_timer)
end

every = worker_settings[:binary_blob_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:binary_blob_purge_interval]) do
enqueue(:binary_blob_purge_timer)
end

every = worker_settings[:notifications_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:notifications_purge_interval]) do
enqueue(:notification_purge_timer)
end

every = worker_settings[:task_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:task_purge_interval]) do
enqueue(:task_purge_timer)
end

every = worker_settings[:compliance_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:compliance_purge_interval]) do
enqueue(:compliance_purge_timer)
end

every = worker_settings[:vim_performance_states_purge_interval]
scheduler.schedule_every(every, :first_in => every) do
scheduler.schedule_every(worker_settings[:vim_performance_states_purge_interval]) do
enqueue(:vim_performance_states_purge_timer)
end

Expand All @@ -240,7 +218,7 @@ def schedules_for_scheduler_role
) { enqueue(:storage_scan_timer) }

schedule_settings_for_ems_refresh.each do |klass, local_every|
scheduler.schedule_every(local_every, :first_in => local_every) do
scheduler.schedule_every(local_every) do
enqueue([:ems_refresh_timer, klass])
end
end
Expand Down Expand Up @@ -312,19 +290,15 @@ def schedules_for_database_operations_role
:tags => %i(database_operations database_maintenance_vacuum_schedule),
) { enqueue(:database_maintenance_vacuum_timer) }

every = worker_settings[:performance_realtime_purging_interval]
first_in = worker_settings[:performance_realtime_purging_start_delay]
scheduler.schedule_every(
every,
:first_in => first_in,
worker_settings[:performance_realtime_purging_interval],
:first_in => worker_settings[:performance_realtime_purging_start_delay],
:tags => [:database_operations, :purge_realtime_timer]
) { enqueue(:metric_purging_purge_realtime_timer) }

every = worker_settings[:performance_rollup_purging_interval]
first_in = worker_settings[:performance_rollup_purging_start_delay]
scheduler.schedule_every(
every,
:first_in => first_in,
worker_settings[:performance_rollup_purging_interval],
:first_in => worker_settings[:performance_rollup_purging_start_delay],
:tags => [:database_operations, :purge_rollup_timer]
) { enqueue(:metric_purging_purge_rollup_timer) }

Expand All @@ -336,11 +310,9 @@ def schedules_for_ems_metrics_coordinator_role
return unless schedule_enabled?("ems_metrics_coordinator")
scheduler = scheduler_for(:ems_metrics_coordinator)
# Schedule - Performance Collection and Performance Purging
every = worker_settings[:performance_collection_interval]
first_in = worker_settings[:performance_collection_start_delay]
scheduler.schedule_every(
every,
:first_in => first_in,
worker_settings[:performance_collection_interval],
:first_in => worker_settings[:performance_collection_start_delay],
:tags => [:ems_metrics_coordinator, :perf_capture_timer]
) { enqueue(:metric_capture_perf_capture_timer) }

Expand All @@ -352,17 +324,15 @@ def schedules_for_event_role
return unless schedule_enabled?(:event)
scheduler = scheduler_for(:event)
# Schedule - Event Purging
interval = worker_settings[:event_streams_purge_interval]
scheduler.schedule_every(
interval,
worker_settings[:event_streams_purge_interval],
:first_in => "300s",
:tags => [:event_stream, :purge_schedule]
) { enqueue(:event_stream_purge_timer) }

# Schedule - Policy Event Purging
interval = worker_settings[:policy_events_purge_interval]
scheduler.schedule_every(
interval,
worker_settings[:policy_events_purge_interval],
:first_in => "300s",
:tags => [:policy_event, :purge_schedule]
) { enqueue(:policy_event_purge_timer) }
Expand Down