Skip to content

Commit

Permalink
Use a constant to represent None for default/blank memoizable values (
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon authored Oct 29, 2023
1 parent 00f80cb commit d9b7549
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
module GoodJob
include GoodJob::Dependencies

# Default, null, blank value placeholder.
NONE = Module.new.freeze

# Default logger for GoodJob; overridden by Rails.logger in Railtie.
DEFAULT_LOGGER = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))

# @!attribute [rw] active_record_parent_class
Expand Down
4 changes: 2 additions & 2 deletions lib/good_job/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ def enqueue_at(active_job, timestamp)
end

# Shut down the thread pool executors.
# @param timeout [nil, Numeric, Symbol] Seconds to wait for active threads.
# @param timeout [nil, Numeric, NONE] Seconds to wait for active threads.
# * +nil+ trigger a shutdown but not wait for it to complete.
# * +-1+ wait until the shutdown is complete.
# * +0+ immediately shutdown and stop any threads.
# * A positive number will wait that many seconds before stopping any remaining active threads.
# @return [void]
def shutdown(timeout: :default)
def shutdown(timeout: NONE)
@capsule&.shutdown(timeout: timeout)
@_async_started = false
end
Expand Down
10 changes: 5 additions & 5 deletions lib/good_job/capsule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ def start(force: false)
end

# Shut down the thread pool executors.
# @param timeout [nil, Numeric, Symbol] Seconds to wait for active threads.
# @param timeout [nil, Numeric, NONE] Seconds to wait for active threads.
# * +-1+ will wait for all active threads to complete.
# * +0+ will interrupt active threads.
# * +N+ will wait at most N seconds and then interrupt active threads.
# * +nil+ will trigger a shutdown but not wait for it to complete.
# @return [void]
def shutdown(timeout: :default)
timeout = @configuration.shutdown_timeout if timeout == :default
def shutdown(timeout: NONE)
timeout = @configuration.shutdown_timeout if timeout == NONE
GoodJob._shutdown_all([@shared_executor, @notifier, @poller, @scheduler, @cron_manager].compact, timeout: timeout)
@startable = false
@running = false
end

# Shutdown and then start the capsule again.
# @param timeout [Numeric, Symbol] Seconds to wait for active threads.
# @param timeout [Numeric, NONE] Seconds to wait for active threads.
# @return [void]
def restart(timeout: :default)
def restart(timeout: NONE)
raise ArgumentError, "Capsule#restart cannot be called with a timeout of nil" if timeout.nil?

shutdown(timeout: timeout)
Expand Down

0 comments on commit d9b7549

Please sign in to comment.