Skip to content

Commit

Permalink
Provide sidekiq a short polling interval for faster checkins (#77)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aortbals committed Mar 29, 2017
1 parent 8124e5c commit 9047657
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 31 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -357,7 +372,7 @@ DEPENDENCIES
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
shoulda-matchers
sidekiq
sidekiq (~> 3.5)
sidekiq-failures
sinatra
skylight
Expand All @@ -372,4 +387,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.10.6
1.14.6
2 changes: 1 addition & 1 deletion app/models/flight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -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: /
6 changes: 3 additions & 3 deletions spec/models/reservation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9047657

Please sign in to comment.