Skip to content

Commit

Permalink
Allow for handler to be injected into ProbeServer
Browse files Browse the repository at this point in the history
  • Loading branch information
jklina committed Jan 2, 2024
1 parent a6ee6db commit dac7ded
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/good_job/http_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def running?
@running.true?
end

def build_future
Concurrent::Future.new { run }
end

private

def start_server
Expand Down
10 changes: 7 additions & 3 deletions lib/good_job/probe_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def self.task_observer(time, output, thread_error) # rubocop:disable Lint/Unused
GoodJob._on_thread_error(thread_error) if thread_error
end

def initialize(port:, app: default_probe_server)
def initialize(port:, handler: nil, app: default_probe_server)
@port = port
@app = app
@handler = handler || default_handler
end

def start
@handler = HttpServer.new(@app, port: @port, logger: GoodJob.logger)
@future = Concurrent::Future.new { @handler.run }
@future = @handler.build_future
@future.add_observer(self.class, :task_observer)
@future.execute
end
Expand All @@ -37,5 +37,9 @@ def default_probe_server
run Middleware::Catchall.new
end
end

def default_handler
HttpServer.new(@app, port: @port, logger: GoodJob.logger)
end
end
end
1 change: 0 additions & 1 deletion spec/lib/good_job/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
options: {},
daemonize?: false,
shutdown_timeout: 100,
idle_timeout: 100
)
allow(GoodJob).to receive_messages(configuration: configuration_mock)
cli = described_class.new([], [], {})
Expand Down

0 comments on commit dac7ded

Please sign in to comment.