Skip to content

Commit

Permalink
Tweaked some timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy committed Jan 13, 2024
1 parent c20e4ae commit 38e243d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/exekutor/internal/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Listener
# @param pool [ThreadPoolExecutor] the thread pool to use
# @param wait_timeout [Integer] the time to listen for notifications
# @param set_db_connection_name [Boolean] whether to set the application name on the DB connection
def initialize(worker_id:, provider:, pool:, queues: nil, min_priority: nil, max_priority: nil, wait_timeout: 60,
def initialize(worker_id:, provider:, pool:, queues: nil, min_priority: nil, max_priority: nil, wait_timeout: 100,
set_db_connection_name: false)
super()
@config = {
Expand Down Expand Up @@ -159,11 +159,13 @@ def wait_for_jobs(connection)
# @yieldparam connection [PG::Connection] the DB connection
def with_pg_connection # :nodoc:
ar_conn = Exekutor::Job.connection_pool.checkout.tap do |conn|
DatabaseConnection.ensure_active! conn
# Action Cable is taking ownership over this database connection, and
# will perform the necessary cleanup tasks
ActiveRecord::Base.connection_pool.remove(conn)
Exekutor::Job.connection_pool.remove conn
end
DatabaseConnection.ensure_active! ar_conn
# Make sure the connection pool does not hold a reference to this thread
Exekutor::Job.connection_handler.clear_active_connections!
pg_conn = ar_conn.raw_connection

verify!(pg_conn)
Expand All @@ -172,7 +174,7 @@ def with_pg_connection # :nodoc:
end
yield pg_conn
ensure
ar_conn.disconnect!
ar_conn&.disconnect!
end

# Verifies the connection
Expand Down Expand Up @@ -201,7 +203,7 @@ def self.parse(payload)
raise Error, "Invalid notification payload: #{payload}"
end
if (missing_keys = JOB_INFO_KEYS.select { |n| job_info[n].blank? }).present?
raise Error, "[Listener] Notification payload is missing #{missing_keys.join(", ")}"
raise Error, "Notification payload is missing #{missing_keys.join(", ")}"
end

job_info
Expand Down
2 changes: 1 addition & 1 deletion lib/exekutor/internal/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Provider
UNKNOWN = Object.new.freeze
private_constant :UNKNOWN

MAX_WAIT_TIMEOUT = 300
MAX_WAIT_TIMEOUT = 100
private_constant :MAX_WAIT_TIMEOUT

# Creates a new provider
Expand Down
2 changes: 1 addition & 1 deletion test/internal/listener_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_corrupt_payload
def test_incomplete_payload
wait_until { listener.send(:listening?) }

listener.send(:logger).expects(:error).with(regexp_matches(/^\[Listener\] Notification payload is missing t$/))
listener.send(:logger).expects(:error).with(regexp_matches(/Notification payload is missing t$/))

Exekutor::Job.connection.exec_query(
%(NOTIFY "#{listener.class::JOB_ENQUEUED_CHANNEL}", 'id:test-id;q:test-queue;p:123')
Expand Down
2 changes: 1 addition & 1 deletion test/internal/provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_wait_timeout_without_poll
provider.stubs(:polling_enabled?).returns(false)
provider.stubs(:next_job_scheduled_at).returns(nil)

assert_equal 300, provider.send(:wait_timeout)
assert_equal 100, provider.send(:wait_timeout)
end

def test_wait_timeout_with_immediate_job
Expand Down

0 comments on commit 38e243d

Please sign in to comment.