Skip to content

Commit

Permalink
Merge pull request #15 from noveng05/master
Browse files Browse the repository at this point in the history
Make timeouts configurable
  • Loading branch information
jacoblipson authored Nov 26, 2020
2 parents 291ea39 + 099d962 commit 3ac4321
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ Journaling provides a number of different configuation options that can be set i
This can be used to configure what `priority` the Delayed Jobs are enqueued with. This will be applied to all the Journaled::Devivery jobs that are created by this application.
Ex: `Journaled.job_priority = 14`
#### `Journaled.http_idle_timeout` (default: 1 second)
The number of seconds a persistent connection is allowed to sit idle before it should no longer be used.
#### `Journaled.http_open_timeout` (default: 15 seconds)
The number of seconds before the :http_handler should timeout while trying to open a new HTTP session.
#### `Journaled.http_read_timeout` (default: 60 seconds)
The number of seconds before the :http_handler should timeout while waiting for a HTTP response.
#### DJ `enqueue` options
Both model-level directives accept additional options to be passed into DelayedJob's `enqueue` method:
Expand Down
5 changes: 4 additions & 1 deletion app/models/journaled/delivery.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Journaled::Delivery
class Journaled::Delivery # rubocop:disable Betterment/ActiveJobPerformable
DEFAULT_REGION = 'us-east-1'.freeze

def initialize(serialized_event:, partition_key:, app_name:)
Expand Down Expand Up @@ -26,6 +26,9 @@ def kinesis_client_config
{
region: ENV.fetch('AWS_DEFAULT_REGION', DEFAULT_REGION),
retry_limit: 0,
http_idle_timeout: Journaled.http_idle_timeout,
http_open_timeout: Journaled.http_open_timeout,
http_read_timeout: Journaled.http_read_timeout,
}.merge(credentials)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/journaled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
module Journaled
mattr_accessor :default_app_name
mattr_accessor(:job_priority) { 20 }
mattr_accessor(:http_idle_timeout) { 5 }
mattr_accessor(:http_open_timeout) { 15 }
mattr_accessor(:http_read_timeout) { 60 }

def development_or_test?
%w(development test).include?(Rails.env)
Expand Down
33 changes: 33 additions & 0 deletions spec/models/journaled/delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,38 @@
expect(subject.kinesis_client_config).to include(access_key_id: 'key_id', secret_access_key: 'secret')
end
end

it "will set http_idle_timeout by default" do
expect(subject.kinesis_client_config).to include(http_idle_timeout: 5)
end

it "will set http_open_timeout by default" do
expect(subject.kinesis_client_config).to include(http_open_timeout: 15)
end

it "will set http_read_timeout by default" do
expect(subject.kinesis_client_config).to include(http_read_timeout: 60)
end

context "when Journaled.http_idle_timeout is specified" do
it "will set http_idle_timeout by specified value" do
allow(Journaled).to receive(:http_idle_timeout).and_return(2)
expect(subject.kinesis_client_config).to include(http_idle_timeout: 2)
end
end

context "when Journaled.http_open_timeout is specified" do
it "will set http_open_timeout by specified value" do
allow(Journaled).to receive(:http_open_timeout).and_return(2)
expect(subject.kinesis_client_config).to include(http_open_timeout: 2)
end
end

context "when Journaled.http_read_timeout is specified" do
it "will set http_read_timeout by specified value" do
allow(Journaled).to receive(:http_read_timeout).and_return(2)
expect(subject.kinesis_client_config).to include(http_read_timeout: 2)
end
end
end
end

0 comments on commit 3ac4321

Please sign in to comment.