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

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Oct 10, 2019

What is :first_in?

We don't want to run all tasks at appliance startup because the appliance would get swamped by all the immediate work. first_in delays the start of some tasks (usually 1 interval) so the work is more evenly distributed. The startup doesn't slam the processor

This is the default behavior for Rufus.

What do we do

  • Drop all :first_in => {every,interval}
  • Condense single use variables

@@ -14,6 +14,7 @@ def initialize(logger, role_schedule, rufus_scheduler)
end

def schedule_every(duration = nil, callable = nil, opts = {}, &block)
callable[:first_in] = duration if callable && callable[:first_in] == :interval
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@Fryguy
Copy link
Member

Fryguy commented Oct 11, 2019

@kbrock Can you give the PR title a more meaning name?

@jrafanie Please review. I'll leave to you to merge.

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

@kbrock kbrock changed the title Scheduler redux Add first_in => interval to scheduler (to reduce the code) Oct 14, 2019
@kbrock kbrock changed the title Add first_in => interval to scheduler (to reduce the code) drop first_in => interval from scheduler Oct 14, 2019
@miq-bot
Copy link
Member

miq-bot commented Oct 14, 2019

Checked commits kbrock/manageiq@0bc1014~...cf245b3 with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍪

@Fryguy
Copy link
Member

Fryguy commented Oct 17, 2019

@jrafanie This looks updated...is this good to go?

@jrafanie
Copy link
Member

✂️ 🔥 ✂️ 🔥 ✂️ 🔥

🍰 🍪 👏 🙇 😍 🎉

@jrafanie jrafanie merged commit 3d507fb into ManageIQ:master Oct 17, 2019
@jrafanie jrafanie added this to the Sprint 123 Ending Oct 28, 2019 milestone Oct 17, 2019
@kbrock kbrock deleted the scheduler_redux branch October 17, 2019 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants