From 9047657d3eb87230aaa3f99ca341547f06c94666 Mon Sep 17 00:00:00 2001 From: Aaron Ortbals Date: Wed, 29 Mar 2017 18:31:58 -0500 Subject: [PATCH] Provide sidekiq a short polling interval for faster checkins (#77) * feat: provide sidekiq a short polling interval for faster checkins This also removes the 1 second `scheduled_at` delay in favor of relying on the slight delay in polling. * wip: update test for the removed delay * feat: robots.txt --- .env.example | 1 + Gemfile | 2 +- Gemfile.lock | 47 ++++++++++++++++++++++----------- app/models/flight.rb | 2 +- config/initializers/sidekiq.rb | 3 +++ public/robots.txt | 4 +-- spec/models/reservation_spec.rb | 6 ++--- 7 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 config/initializers/sidekiq.rb diff --git a/.env.example b/.env.example index 79d65626..703f1699 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ MAILER_DEFAULT_REPLY_TO=test@localhost:3000 DEPLOY_BRANCH=master DEPLOY_USER=deploy DEPLOY_PORT=22 +SIDEKIQ_POLLING_INTERVAL=1 MAILER_ADDRESS= MAILER_DOMAIN= MAILER_USERNAME= diff --git a/Gemfile b/Gemfile index ad6c22f1..cbcf2b45 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'typhoeus', '~> 0.7' # HTTP request client gem 'devise', '~> 3.4' # Authentication -gem 'sidekiq' # Background job processing queue +gem 'sidekiq', '~> 3.5' # Background job processing queue gem 'sinatra', :require => nil # Required for sidekiq web UI gem 'sidekiq-failures' # Track sidekiq failures diff --git a/Gemfile.lock b/Gemfile.lock index 805f804a..c2a3c564 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,8 +49,23 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) - celluloid (0.16.0) - timers (~> 4.0.0) + celluloid (0.17.3) + celluloid-essentials + celluloid-extras + celluloid-fsm + celluloid-pool + celluloid-supervision + timers (>= 4.1.1) + celluloid-essentials (0.20.5) + timers (>= 4.1.1) + celluloid-extras (0.20.5) + timers (>= 4.1.1) + celluloid-fsm (0.20.5) + timers (>= 4.1.1) + celluloid-pool (0.20.5) + timers (>= 4.1.1) + celluloid-supervision (0.20.6) + timers (>= 4.1.1) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -60,7 +75,7 @@ GEM execjs coffee-script-source (1.8.0) columnize (0.9.0) - connection_pool (2.1.1) + connection_pool (2.2.1) coveralls (0.8.10) json (~> 1.8) rest-client (>= 1.6.8, < 2) @@ -111,7 +126,7 @@ GEM guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) hike (1.2.3) - hitimes (1.2.2) + hitimes (1.2.4) http-cookie (1.0.2) domain_name (~> 0.5) i18n (0.7.0) @@ -122,7 +137,7 @@ GEM rails-dom-testing (~> 1.0) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.3) + json (1.8.6) json-schema (2.5.0) addressable (~> 2.3) json-schema-rspec (0.0.4) @@ -211,8 +226,8 @@ GEM ffi (>= 0.5.0) rdoc (4.2.0) json (~> 1.4) - redis (3.2.0) - redis-namespace (1.5.1) + redis (3.3.3) + redis-namespace (1.5.3) redis (~> 3.0, >= 3.0.4) responders (2.0.2) railties (>= 4.2.0.alpha, < 5) @@ -260,12 +275,12 @@ GEM shellany (0.0.1) shoulda-matchers (2.7.0) activesupport (>= 3.0.0) - sidekiq (3.3.0) - celluloid (>= 0.16.0) - connection_pool (>= 2.0.0) - json - redis (>= 3.0.6) - redis-namespace (>= 1.3.1) + sidekiq (3.5.4) + celluloid (~> 0.17.2) + connection_pool (~> 2.2, >= 2.2.0) + json (~> 1.0) + redis (~> 3.2, >= 3.2.1) + redis-namespace (~> 1.5, >= 1.5.2) sidekiq-failures (0.4.5) sidekiq (>= 2.16.0) simplecov (0.11.1) @@ -298,7 +313,7 @@ GEM thread_safe (0.3.5) tilt (1.4.1) timecop (0.7.1) - timers (4.0.1) + timers (4.1.2) hitimes tins (1.6.0) turbolinks (2.5.3) @@ -357,7 +372,7 @@ DEPENDENCIES sass-rails (~> 5.0) sdoc (~> 0.4.0) shoulda-matchers - sidekiq + sidekiq (~> 3.5) sidekiq-failures sinatra skylight @@ -372,4 +387,4 @@ DEPENDENCIES webmock BUNDLED WITH - 1.10.6 + 1.14.6 diff --git a/app/models/flight.rb b/app/models/flight.rb index 00d984b5..8d9e9ec4 100644 --- a/app/models/flight.rb +++ b/app/models/flight.rb @@ -37,7 +37,7 @@ def scheduled? end def schedule_checkin - schedule_at = departure_time - 1.day + 1.second + schedule_at = departure_time - 1.day job = CheckinJob.set(wait_until: schedule_at).perform_later(self) checkin = Checkin.find_or_initialize_by(flight: self) checkin.update({ diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 00000000..95ab0e2e --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,3 @@ +Sidekiq.configure_server do |config| + config.average_scheduled_poll_interval = ENV['SIDEKIQ_POLLING_INTERVAL'].present? ? ENV['SIDEKIQ_POLLING_INTERVAL'].to_i : 1 +end diff --git a/public/robots.txt b/public/robots.txt index 3c9c7c01..f6ca098a 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1,5 @@ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / +User-agent: * +Disallow: / diff --git a/spec/models/reservation_spec.rb b/spec/models/reservation_spec.rb index 44b7d216..61f73f6a 100644 --- a/spec/models/reservation_spec.rb +++ b/spec/models/reservation_spec.rb @@ -138,15 +138,15 @@ def recorded(cassette='record locator view multi LAX 2016-03-18') end end - it 'enqueues the checkin 23hr59m59s before departure' do + it 'enqueues the checkin 24hrs before departure' do VCR.use_cassette(cassette) do Timecop.freeze(Time.zone.parse('1 Jan 2015')) do subject jobs = ActiveJob::Base.queue_adapter.enqueued_jobs.sort_by {|j| j[:at] } enqueued_at = Time.zone.at(jobs.first[:at]) enqueued_at_2 = Time.zone.at(jobs.last[:at]) - expect(enqueued_at).to eq(Time.zone.parse("Wed, 23 Mar 2016 22:05:01 UTC +00:00")) - expect(enqueued_at_2).to eq(Time.zone.parse("Sun, 27 Mar 2016 12:35:01 UTC +00:00")) + expect(enqueued_at).to eq(Time.zone.parse("Wed, 23 Mar 2016 22:05:00 UTC +00:00")) + expect(enqueued_at_2).to eq(Time.zone.parse("Sun, 27 Mar 2016 12:35:00 UTC +00:00")) end end end